IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

excel et fichier partagé [Débutant]


Sujet :

VB.NET

  1. #1
    Membre à l'essai
    Homme Profil pro
    Ingénieur mécanique
    Inscrit en
    Septembre 2019
    Messages
    34
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Ingénieur mécanique
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2019
    Messages : 34
    Points : 14
    Points
    14
    Par défaut excel et fichier partagé
    Bonjour à tous !

    Question : est-ce qu'il est possible de piloter par VB.net (sous visual studio 2019) un fichier excel partagé (type shared workbook) ?
    et si oui auriez vous des exemples de codes à me montrer svp ?

    J'ai pas mal cherché sur internet mais globalement la seule réponse à ce genre de question c'est une base de donnée serait plus indiquée.
    (Sauf que dans mon cas je n'ai pas la possibilité de faire une base de donnée (manque de connaissance et pas forcément adapté pour le projet)).

    Aujourd'hui j'arrive à faire un programme qui ouvre excel, écrit les infos que je veux sauvegarder dans une cellule et ferme excel.

    Mais ce n'est pas suffisant : j'aimerais que jusqu'à 30 PC ouvrent le fichier en simultané, et y écrivent sans conflit, et qu'à la fin le fichier soit suavegardé.

    Est-ce que pour vous c'est possible ?

    Merci par avance pour vos réponses !

  2. #2
    Membre averti
    Homme Profil pro
    IT Manager
    Inscrit en
    Janvier 2018
    Messages
    220
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : Belgique

    Informations professionnelles :
    Activité : IT Manager
    Secteur : Santé

    Informations forums :
    Inscription : Janvier 2018
    Messages : 220
    Points : 319
    Points
    319
    Par défaut
    Bonjour,

    J'en doute...
    Si un utilisateur à le fichier ouvert via ton application, un autre ne pourra pas l'ouvrir pour écrire dedans...

    C'est la même chose pour le fichier en lui même...
    Tu ne peux pas avoir deux personnes en même temps en écriture dessus.

    Si Excel ne peut pas le gérer, VB.NET ne saura pas le gérer non plus.

    Tes seules chances sont de passer par une base de données ou à la limite, un fichier texte dans lequel tu pourras faire des "append" mais c'est merdique si tu veux mon avis

    Je partirais sur une base de donnée... et si tu as déjà des licences Offices365, Access ne te coûtera rien et est très fréquent avec VB.NET.
    Tu trouveras facilement de la doc sur comment utiliser tout ça et puis si jamais, le forum est là pour aider

  3. #3
    Membre à l'essai
    Homme Profil pro
    Ingénieur mécanique
    Inscrit en
    Septembre 2019
    Messages
    34
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Ingénieur mécanique
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2019
    Messages : 34
    Points : 14
    Points
    14
    Par défaut
    Re bonjour Thovan !
    Décidemment tu es toujours là pour m'aider ^^ Merci !

    C'est ce que je craignais ..

    Le soucis c'est qu'il me reste moins de 3 jours pour apprendre a faire une base de donnée et coder mon application en conséquence.

    Si tu te souvient, j'avais déjà demandé de l'aide sur ce forum pour créer un "timer" et tu m'avais lancé sur la piste des threads.
    Là je viens de finir l'application.
    Seul bémol, elle est tournée excel et ne marche qu'avec un seul utilisateur.

    Bref : je vais ouvrir un nouveau sujet concernant les Bases de données.

  4. #4
    Membre averti
    Homme Profil pro
    IT Manager
    Inscrit en
    Janvier 2018
    Messages
    220
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : Belgique

    Informations professionnelles :
    Activité : IT Manager
    Secteur : Santé

    Informations forums :
    Inscription : Janvier 2018
    Messages : 220
    Points : 319
    Points
    319
    Par défaut
    Elle est tournée Excel...
    Tu veux dire, les données sont dans Excel ??

    Très franchement, même si tu y arrives avec Excel... (et crois-moi tu vas galérer car Excel peut-être piloté en VBA, différent du VB.NET et franchement pas évident à manipuler/traduire en VB.NET) les performances seront merdiques .

    En 3 jours ça risque d'être coton aussi!

    Je t'aiderai du mieux que je peux pendant ma journée de travail mais ça dépendra de la charge de boulot que j'ai .

  5. #5
    Membre à l'essai
    Homme Profil pro
    Ingénieur mécanique
    Inscrit en
    Septembre 2019
    Messages
    34
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Ingénieur mécanique
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2019
    Messages : 34
    Points : 14
    Points
    14
    Par défaut
    En fait l'appli est dédiée à excel car c'est ce qu'on m'avait imposé :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
     
     
    Imports System.ComponentModel
    Imports System.IO
    Imports System.Text
     
    Imports Excel = Microsoft.Office.Interop.Excel
     
    Public Class DEMO
     
        'Dim pathwriter As StreamWriter
        Dim reset As Boolean = False 'for reset bouton
        Dim resetcounter As Integer = 0
        Dim flagtimer As Boolean = False 'flag to activate the date registration
        Dim Fronts, Backs, Elem, Screws, Boxes, Wires, Poly, Wf, others As Integer 'flags
        Dim i As Integer = 1 'counter used to count the number of line in the excel file
        Dim k As Integer = 1 'counter used like i but for downtime
        Dim cellN As String 'Cell Number
        Dim df1, df2, db1, db2, de1, de2, ds1, ds2, dx1, dx2, dw1, dw2, dp1, dp2, dwf1, dwf2, do1, do2, path, path2, path3 As String
        Dim df, dfR, dfe, db, dbr, dbe, de, der, dee, ds, dsr, dse, dx, dxr, dxe, dw, dwr, dwe, dp, dpr, dpe, dwf, dwfr, dwfe, dot, dotr, dote As Date
        Dim dreal, dreale As Date 'used to calcul the real downtime
        Dim dstop As String 'real downtime
        Dim ApExcel As New Excel.Application 'Application Excel
        Dim wbExcel As Excel.Workbook 'Classeur Excel
        Dim wsExcel As Excel.Worksheet 'Feuille Excel
        'Dim mRow As Integer = CInt(ws.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row)
        'Dim mColumn As Integer = CInt(ws.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Column)
     
        Private Sub butReset_Click(sender As Object, e As EventArgs) Handles butReset.Click
            'Reset button increase/set a flag to have the status of reset
            If resetcounter = 0 Then
                resetcounter = resetcounter + 1
                reset = True
                butReset.BackColor = Color.Green
            Else
                resetcounter = 0
                reset = False
                butReset.BackColor = Color.LightGray
            End If
        End Sub
     
     
        Private Sub butOthers_Click(sender As Object, e As EventArgs) Handles butOthers.Click
            'If the operator click once on the button, this one become amber : that's mean that the cell is running out of parts
            'when the operator click a second time, the button become red and the date is saved 
            'when reset button is pressed, it will light off the buttons pressed next, the date will be registered again : the difference of the 2 dates gives the real downtime
            'for the cell
            If reset = False Then
                If others = 0 Then
                    butOthers.BackColor = Color.Orange
                    others = others + 1
                    dot = DateTime.Now
                ElseIf others = 1 Then
                    butOthers.BackColor = Color.Red
                    others = others + 1
                    dotr = DateTime.Now
                    If flagtimer = False Then
                        flagtimer = True
                        dreal = DateTime.Now
                    End If
                End If
            ElseIf reset = True Then
                others = 0
                butOthers.BackColor = Color.LightGray
                If Fronts = 0 And Backs = 0 And Elem = 0 And Screws = 0 And Boxes = 0 And Wires = 0 And Poly = 0 And Wf = 0 And others = 0 Then
                    flagtimer = False
                    dreale = DateTime.Now
                    dstop = DateDiff(DateInterval.Second, dreal, dreale)
                    'pathwriter = New StreamWriter(path2, True, Encoding.Unicode)
                    'pathwriter.WriteLine("Stoppage time of " & "Cell N" & cellN & "; " & TimeSpan.FromSeconds(dstop).ToString("hh\:mm\:ss"))
                    'pathwriter.Close()
                    ApExcel.Workbooks.Open(path3)
                    ApExcel.Sheets(2).select
                    ApExcel.Cells(k, 1) = cellN
                    ApExcel.Cells(k, 2) = TimeSpan.FromSeconds(dstop).ToString("hh\:mm\:ss")
                    ApExcel.ActiveWorkbook.Close(True)
                    ApExcel.Quit()
                    k = k + 1
                End If
                dote = DateTime.Now
                do1 = DateDiff(DateInterval.Second, dotr, dote)
                do2 = DateDiff(DateInterval.Second, dot, dote)
                'pathwriter = New StreamWriter(path, True, Encoding.Unicode)
                'pathwriter.WriteLine("Cell" & cellN & " ; " & "Others" & " ; " & dot & " ; " & TimeSpan.FromSeconds(do2).ToString("hh\:mm\:ss") & " ; " & dotr & " ; " & TimeSpan.FromSeconds(do1).ToString("hh\:mm\:ss"))
                'pathwriter.Close()
                ApExcel.Workbooks.Open(path3)
                ApExcel.Sheets(1).select
                ApExcel.Cells(i, 1) = cellN
                ApExcel.Cells(i, 2) = "others"
                ApExcel.Cells(i, 3) = dot
                ApExcel.Cells(i, 4) = TimeSpan.FromSeconds(do2).ToString("hh\:mm\:ss")
                ApExcel.Cells(i, 5) = dotr
                ApExcel.Cells(i, 6) = TimeSpan.FromSeconds(do1).ToString("hh\:mm\:ss")
                i = i + 1
                ApExcel.ActiveWorkbook.Close(True)
                ApExcel.Quit()
            End If
        End Sub
     
        Private Sub butWires_Click(sender As Object, e As EventArgs) Handles butWires.Click
            If reset = False Then
                If Wires = 0 Then
                    butWires.BackColor = Color.Orange
                    Wires = Wires + 1
                    dw = DateTime.Now
                ElseIf Wires = 1 Then
                    butWires.BackColor = Color.Red
                    Wires = Wires + 1
                    dwr = DateTime.Now
                    If flagtimer = False Then
                        flagtimer = True
                        dreal = DateTime.Now
                    End If
                End If
            ElseIf reset = True Then
                Wires = 0
                butWires.BackColor = Color.LightGray
                If Fronts = 0 And Backs = 0 And Elem = 0 And Screws = 0 And Boxes = 0 And Wires = 0 And Poly = 0 And Wf = 0 And others = 0 Then
                    flagtimer = False
                    dreale = DateTime.Now
                    dstop = DateDiff(DateInterval.Second, dreal, dreale)
                    'pathwriter = New StreamWriter(path2, True, Encoding.Unicode)
                    'pathwriter.WriteLine("Stoppage time of " & "Cell N" & cellN & "; " & TimeSpan.FromSeconds(dstop).ToString("hh\:mm\:ss"))
                    'pathwriter.Close()
                    ApExcel.Workbooks.Open(path3)
                    ApExcel.Sheets(2).select
                    ApExcel.Cells(k, 1) = cellN
                    ApExcel.Cells(k, 2) = TimeSpan.FromSeconds(dstop).ToString("hh\:mm\:ss")
                    ApExcel.ActiveWorkbook.Close(True)
                    ApExcel.Quit()
                    k = k + 1
                End If
     
                dwe = DateTime.Now
                dw1 = DateDiff(DateInterval.Second, dwr, dwe)
                dw2 = DateDiff(DateInterval.Second, dw, dwe)
                'pathwriter = New StreamWriter(path, True, Encoding.Unicode)
                'pathwriter.WriteLine("Cell" & cellN & " ; " & "Wires" & " ; " & dw & " ; " & TimeSpan.FromSeconds(dw2).ToString("hh\:mm\:ss") & " ; " & dwr & " ; " & TimeSpan.FromSeconds(dw1).ToString("hh\:mm\:ss"))
                'pathwriter.Close()
                ApExcel.Workbooks.Open(path3)
                ApExcel.Sheets(1).select
                ApExcel.Cells(i, 1) = cellN
                ApExcel.Cells(i, 2) = "Wires"
                ApExcel.Cells(i, 3) = dw
                ApExcel.Cells(i, 4) = TimeSpan.FromSeconds(dw2).ToString("hh\:mm\:ss")
                ApExcel.Cells(i, 5) = dwr
                ApExcel.Cells(i, 6) = TimeSpan.FromSeconds(dw1).ToString("hh\:mm\:ss")
                i = i + 1
                ApExcel.ActiveWorkbook.Close(True)
                ApExcel.Quit()
            End If
     
        End Sub
     
        Private Sub ButScrews_Click(sender As Object, e As EventArgs) Handles butScrews.Click
            If reset = False Then
                If Screws = 0 Then
                    butScrews.BackColor = Color.Orange
                    Screws = Screws + 1
                    ds = DateTime.Now
                ElseIf Screws = 1 Then
                    butScrews.BackColor = Color.Red
                    Screws = Screws + 1
                    dsr = DateTime.Now
                    If flagtimer = False Then
                        flagtimer = True
                        dreal = DateTime.Now
                    End If
                End If
            ElseIf reset = True Then
                butScrews.BackColor = Color.LightGray
                Screws = 0
                If Fronts = 0 And Backs = 0 And Elem = 0 And Screws = 0 And Boxes = 0 And Wires = 0 And Poly = 0 And Wf = 0 And others = 0 Then
                    flagtimer = False
                    dreale = DateTime.Now
                    dstop = DateDiff(DateInterval.Second, dreal, dreale)
                    'pathwriter = New StreamWriter(path2, True, Encoding.Unicode)
                    'pathwriter.WriteLine("Stoppage time of " & "Cell N" & cellN & "; " & TimeSpan.FromSeconds(dstop).ToString("hh\:mm\:ss"))
                    'pathwriter.Close()
                    ApExcel.Workbooks.Open(path3)
                    ApExcel.Sheets(2).select
                    ApExcel.Cells(k, 1) = cellN
                    ApExcel.Cells(k, 2) = TimeSpan.FromSeconds(dstop).ToString("hh\:mm\:ss")
                    ApExcel.ActiveWorkbook.Close(True)
                    ApExcel.Quit()
                    k = k + 1
     
                End If
     
                dse = DateTime.Now
                ds1 = DateDiff(DateInterval.Second, dsr, dse)
                ds2 = DateDiff(DateInterval.Second, ds, dse)
                'pathwriter = New StreamWriter(path, True, Encoding.Unicode)
                'pathwriter.WriteLine("Cell" & cellN & " ; " & "Screws" & " ; " & ds & " ; " & TimeSpan.FromSeconds(ds2).ToString("hh\:mm\:ss") & " ; " & dsr & " ; " & TimeSpan.FromSeconds(ds1).ToString("hh\:mm\:ss"))
                'pathwriter.Close()
                ApExcel.Workbooks.Open(path3)
                ApExcel.Sheets(1).select
                ApExcel.Cells(i, 1) = cellN
                ApExcel.Cells(i, 2) = "Screws"
                ApExcel.Cells(i, 3) = ds
                ApExcel.Cells(i, 4) = TimeSpan.FromSeconds(ds2).ToString("hh\:mm\:ss")
                ApExcel.Cells(i, 5) = dsr
                ApExcel.Cells(i, 6) = TimeSpan.FromSeconds(ds1).ToString("hh\:mm\:ss")
                i = i + 1
                ApExcel.ActiveWorkbook.Close(True)
                ApExcel.Quit()
            End If
        End Sub
     
        Private Sub ButPoly_Click(sender As Object, e As EventArgs) Handles butPoly.Click
            If reset = False Then
                If Poly = 0 Then
                    butPoly.BackColor = Color.Orange
                    Poly = Poly + 1
                    dp = DateTime.Now
                ElseIf Poly = 1 Then
                    butPoly.BackColor = Color.Red
                    Poly = Poly + 1
                    dpr = DateTime.Now
                    If flagtimer = False Then
                        flagtimer = True
                        dreal = DateTime.Now
                    End If
                End If
     
            ElseIf reset = True Then
                butPoly.BackColor = Color.LightGray
                Poly = 0
                If Fronts = 0 And Backs = 0 And Elem = 0 And Screws = 0 And Boxes = 0 And Wires = 0 And Poly = 0 And Wf = 0 And others = 0 Then
                    flagtimer = False
                    dreale = DateTime.Now
                    dstop = DateDiff(DateInterval.Second, dreal, dreale)
                    'pathwriter = New StreamWriter(path2, True, Encoding.Unicode)
                    'pathwriter.WriteLine("Stoppage time of " & "Cell N" & cellN & "; " & TimeSpan.FromSeconds(dstop).ToString("hh\:mm\:ss"))
                    'pathwriter.Close()
                    ApExcel.Workbooks.Open(path3)
                    ApExcel.Sheets(2).select
                    ApExcel.Cells(k, 1) = cellN
                    ApExcel.Cells(k, 2) = TimeSpan.FromSeconds(dstop).ToString("hh\:mm\:ss")
                    ApExcel.ActiveWorkbook.Close(True)
                    ApExcel.Quit()
                    k = k + 1
                End If
                Poly = 0
                dpe = DateTime.Now
                dp1 = DateDiff(DateInterval.Second, dpr, dpe)
                dp2 = DateDiff(DateInterval.Second, dp, dpe)
                'pathwriter = New StreamWriter(path, True, Encoding.Unicode)
                'pathwriter.WriteLine("Cell" & cellN & " ; " & "Poly" & " ; " & dp & " ; " & TimeSpan.FromSeconds(dp2).ToString("hh\:mm\:ss") & " ; " & dpr & " ; " & TimeSpan.FromSeconds(dp1).ToString("hh\:mm\:ss"))
                'pathwriter.Close()
                ApExcel.Workbooks.Open(path3)
                ApExcel.Sheets(1).select
                ApExcel.Cells(i, 1) = cellN
                ApExcel.Cells(i, 2) = "Poly"
                ApExcel.Cells(i, 3) = dp
                ApExcel.Cells(i, 4) = TimeSpan.FromSeconds(dp2).ToString("hh\:mm\:ss")
                ApExcel.Cells(i, 5) = dpr
                ApExcel.Cells(i, 6) = TimeSpan.FromSeconds(dp1).ToString("hh\:mm\:ss")
                i = i + 1
                ApExcel.ActiveWorkbook.Close(True)
                ApExcel.Quit()
            End If
        End Sub
     
     
        Private Sub butboxes_Click(sender As Object, e As EventArgs) Handles butboxes.Click
            If reset = False Then
                If Boxes = 0 Then
                    butboxes.BackColor = Color.Orange
                    Boxes = Boxes + 1
                    dx = DateTime.Now
                ElseIf Boxes = 1 Then
                    butboxes.BackColor = Color.Red
                    Boxes = Boxes + 1
                    dxr = DateTime.Now
                    If flagtimer = False Then
                        flagtimer = True
                        dreal = DateTime.Now
                    End If
                End If
            ElseIf reset = True Then
                butboxes.BackColor = Color.LightGray
                Boxes = 0
                If Fronts = 0 And Backs = 0 And Elem = 0 And Screws = 0 And Boxes = 0 And Wires = 0 And Poly = 0 And Wf = 0 And others = 0 Then
                    flagtimer = False
                    dreale = DateTime.Now
                    dstop = DateDiff(DateInterval.Second, dreal, dreale)
                    'pathwriter = New StreamWriter(path2, True, Encoding.Unicode)
                    'pathwriter.WriteLine("Stoppage time of " & "Cell N" & cellN & "; " & TimeSpan.FromSeconds(dstop).ToString("hh\:mm\:ss"))
                    'pathwriter.Close()
                    ApExcel.Workbooks.Open(path3)
                    ApExcel.Sheets(2).select
                    ApExcel.Cells(k, 1) = cellN
                    ApExcel.Cells(k, 2) = TimeSpan.FromSeconds(dstop).ToString("hh\:mm\:ss")
                    ApExcel.ActiveWorkbook.Close(True)
                    ApExcel.Quit()
                    k = k + 1
                End If
     
                dxe = DateTime.Now
                dx1 = DateDiff(DateInterval.Second, dxr, dxe)
                dx2 = DateDiff(DateInterval.Second, dx, dxe)
                'pathwriter = New StreamWriter(path, True, Encoding.Unicode)
                'pathwriter.WriteLine("Cell" & cellN & " ; " & "Boxes" & " ; " & dx & " ; " & TimeSpan.FromSeconds(dx2).ToString("hh\:mm\:ss") & " ; " & dxr & " ; " & TimeSpan.FromSeconds(dx1).ToString("hh\:mm\:ss"))
                'pathwriter.Close()
                ApExcel.Workbooks.Open(path3)
                ApExcel.Sheets(1).select
                ApExcel.Cells(i, 1) = cellN
                ApExcel.Cells(i, 2) = "Boxes"
                ApExcel.Cells(i, 3) = dx
                ApExcel.Cells(i, 4) = TimeSpan.FromSeconds(dx2).ToString("hh\:mm\:ss")
                ApExcel.Cells(i, 5) = dxr
                ApExcel.Cells(i, 6) = TimeSpan.FromSeconds(dx1).ToString("hh\:mm\:ss")
                i = i + 1
                ApExcel.ActiveWorkbook.Close(True)
                ApExcel.Quit()
            End If
        End Sub
     
     
        Private Sub butwall_Click(sender As Object, e As EventArgs) Handles butwall.Click
            If reset = False Then
                If Wf = 0 Then
                    butwall.BackColor = Color.Orange
                    Wf = Wf + 1
                    dwf = DateTime.Now
                ElseIf Wf = 1 Then
                    butwall.BackColor = Color.Red
                    Wf = Wf + 1
                    dwfr = DateTime.Now
                    If flagtimer = False Then
                        flagtimer = True
                        dreal = DateTime.Now
                    End If
                End If
            ElseIf reset = True Then
                butwall.BackColor = Color.LightGray
                Wf = 0
                If Fronts = 0 And Backs = 0 And Elem = 0 And Screws = 0 And Boxes = 0 And Wires = 0 And Poly = 0 And Wf = 0 And others = 0 Then
                    flagtimer = False
                    dreale = DateTime.Now
                    dstop = DateDiff(DateInterval.Second, dreal, dreale)
                    'pathwriter = New StreamWriter(path2, True, Encoding.Unicode)
                    'pathwriter.WriteLine("Stoppage time of " & "Cell N" & cellN & "; " & TimeSpan.FromSeconds(dstop).ToString("hh\:mm\:ss"))
                    'pathwriter.Close()
                    ApExcel.Workbooks.Open(path3)
                    ApExcel.Sheets(2).select
                    ApExcel.Cells(k, 1) = cellN
                    ApExcel.Cells(k, 2) = TimeSpan.FromSeconds(dstop).ToString("hh\:mm\:ss")
                    ApExcel.ActiveWorkbook.Close(True)
                    ApExcel.Quit()
                    k = k + 1
                End If
     
                dwfe = DateTime.Now
                dwf1 = DateDiff(DateInterval.Second, dwfr, dwfe)
                dwf2 = DateDiff(DateInterval.Second, dwf, dwfe)
                'pathwriter = New StreamWriter(path, True, Encoding.Unicode)
                'pathwriter.WriteLine("Cell" & cellN & " ; " & "Wallframes" & " ; " & dwf & " ; " & TimeSpan.FromSeconds(dwf2).ToString("hh\:mm\:ss") & " ; " & dwfr & " ; " & TimeSpan.FromSeconds(dwf1).ToString("hh\:mm\:ss"))
                'pathwriter.Close()
                ApExcel.Workbooks.Open(path3)
                ApExcel.Sheets(1).select
                ApExcel.Cells(i, 1) = cellN
                ApExcel.Cells(i, 2) = "WallFrames"
                ApExcel.Cells(i, 3) = dwf
                ApExcel.Cells(i, 4) = TimeSpan.FromSeconds(dwf2).ToString("hh\:mm\:ss")
                ApExcel.Cells(i, 5) = dwfr
                ApExcel.Cells(i, 6) = TimeSpan.FromSeconds(dwf1).ToString("hh\:mm\:ss")
                i = i + 1
                ApExcel.ActiveWorkbook.Close(True)
                ApExcel.Quit()
            End If
        End Sub
     
     
     
        Private Sub butElem_Click(sender As Object, e As EventArgs) Handles butElem.Click
            If reset = False Then
                If Elem = 0 Then
                    butElem.BackColor = Color.Orange
                    Elem = Elem + 1
                    de = DateTime.Now
                ElseIf Elem = 1 Then
                    butElem.BackColor = Color.Red
                    Elem = Elem + 1
                    der = DateTime.Now
                    If flagtimer = False Then
                        flagtimer = True
                        dreal = DateTime.Now
                    End If
                End If
            ElseIf reset = True Then
                butElem.BackColor = Color.LightGray
                Elem = 0
                If Fronts = 0 And Backs = 0 And Elem = 0 And Screws = 0 And Boxes = 0 And Wires = 0 And Poly = 0 And Wf = 0 And others = 0 Then
                    flagtimer = False
                    dreale = DateTime.Now
                    dstop = DateDiff(DateInterval.Second, dreal, dreale)
                    'pathwriter = New StreamWriter(path2, True, Encoding.Unicode)
                    'pathwriter.WriteLine("Stoppage time of " & "Cell N" & cellN & "; " & TimeSpan.FromSeconds(dstop).ToString("hh\:mm\:ss"))
                    'pathwriter.Close()
                    ApExcel.Workbooks.Open(path3)
                    ApExcel.Sheets(2).select
                    ApExcel.Cells(k, 1) = cellN
                    ApExcel.Cells(k, 2) = TimeSpan.FromSeconds(dstop).ToString("hh\:mm\:ss")
                    ApExcel.ActiveWorkbook.Close(True)
                    ApExcel.Quit()
                    k = k + 1
     
                End If
     
                dee = DateTime.Now
                de1 = DateDiff(DateInterval.Second, der, dee)
                de2 = DateDiff(DateInterval.Second, de, dee)
                'pathwriter = New StreamWriter(path, True, Encoding.Unicode)
                'pathwriter.WriteLine("Cell" & cellN & " ; " & "Elements" & " ; " & de & " ; " & TimeSpan.FromSeconds(de2).ToString("hh\:mm\:ss") & " ; " & der & " ; " & TimeSpan.FromSeconds(de1).ToString("hh\:mm\:ss"))
                'pathwriter.Close()
                ApExcel.Workbooks.Open(path3)
                ApExcel.Sheets(1).select
                ApExcel.Cells(i, 1) = cellN
                ApExcel.Cells(i, 2) = "Elements"
                ApExcel.Cells(i, 3) = de
                ApExcel.Cells(i, 4) = TimeSpan.FromSeconds(de2).ToString("hh\:mm\:ss")
                ApExcel.Cells(i, 5) = der
                ApExcel.Cells(i, 6) = TimeSpan.FromSeconds(de1).ToString("hh\:mm\:ss")
                i = i + 1
                ApExcel.ActiveWorkbook.Close(True)
                ApExcel.Quit()
            End If
        End Sub
     
     
        Private Sub butBack_Click(sender As Object, e As EventArgs) Handles butBack.Click
            If reset = False Then
                If Backs = 0 Then
                    butBack.BackColor = Color.Orange
                    Backs = Backs + 1
                    db = DateTime.Now
                ElseIf Backs = 1 Then
                    butBack.BackColor = Color.Red
                    Backs = Backs + 1
                    dbr = DateTime.Now
                    If flagtimer = False Then
                        flagtimer = True
                        dreal = DateTime.Now
                    End If
                End If
            ElseIf reset = True Then
                butBack.BackColor = Color.LightGray
                Backs = 0
                If Fronts = 0 And Backs = 0 And Elem = 0 And Screws = 0 And Boxes = 0 And Wires = 0 And Poly = 0 And Wf = 0 And others = 0 Then
                    flagtimer = False
                    dreale = DateTime.Now
                    dstop = DateDiff(DateInterval.Second, dreal, dreale)
                    'pathwriter = New StreamWriter(path2, True, Encoding.Unicode)
                    'pathwriter.WriteLine("Stoppage time of " & "Cell N" & cellN & "; " & TimeSpan.FromSeconds(dstop).ToString("hh\:mm\:ss"))
                    'pathwriter.Close()
                    ApExcel.Workbooks.Open(path3)
                    ApExcel.Sheets(2).select
                    ApExcel.Cells(k, 1) = cellN
                    ApExcel.Cells(k, 2) = TimeSpan.FromSeconds(dstop).ToString("hh\:mm\:ss")
                    ApExcel.ActiveWorkbook.Close(True)
                    ApExcel.Quit()
                    k = k + 1
                End If
     
                dbe = DateTime.Now
                db1 = DateDiff(DateInterval.Second, dbr, dbe)
                db2 = DateDiff(DateInterval.Second, db, dbe)
                'pathwriter = New StreamWriter(path, True, Encoding.Unicode)
                'pathwriter.WriteLine("Cell" & cellN & " ; " & "Backs" & " ; " & db & " ; " & TimeSpan.FromSeconds(db2).ToString("hh\:mm\:ss") & " ; " & dbr & " ; " & TimeSpan.FromSeconds(db1).ToString("hh\:mm\:ss"))
                'pathwriter.Close()
                ApExcel.Workbooks.Open(path3)
                ApExcel.Sheets(1).select
                ApExcel.Cells(i, 1) = cellN
                ApExcel.Cells(i, 2) = "Backs"
                ApExcel.Cells(i, 3) = dbe
                ApExcel.Cells(i, 4) = TimeSpan.FromSeconds(db2).ToString("hh\:mm\:ss")
                ApExcel.Cells(i, 5) = dbr
                ApExcel.Cells(i, 6) = TimeSpan.FromSeconds(db1).ToString("hh\:mm\:ss")
                i = i + 1
                ApExcel.ActiveWorkbook.Close(True)
                ApExcel.Quit()
            End If
        End Sub
     
        Private Sub butFronts_Click(sender As Object, e As EventArgs) Handles butFronts.Click
            If reset = False Then
                If Fronts = 0 Then
                    butFronts.BackColor = Color.Orange
                    Fronts = Fronts + 1
                    df = DateTime.Now
                ElseIf Fronts = 1 Then
                    butFronts.BackColor = Color.Red
                    Fronts = Fronts + 1
                    dfR = DateTime.Now
                    If flagtimer = False Then
                        flagtimer = True
                        dreal = DateTime.Now
                    End If
                End If
            ElseIf reset = True Then
                butFronts.BackColor = Color.LightGray
                Fronts = 0
                If Fronts = 0 And Backs = 0 And Elem = 0 And Screws = 0 And Boxes = 0 And Wires = 0 And Poly = 0 And Wf = 0 And others = 0 Then
                    flagtimer = False
                    dreale = DateTime.Now
                    dstop = DateDiff(DateInterval.Second, dreal, dreale)
                    'pathwriter = New StreamWriter(path2, True, Encoding.Unicode)
                    'pathwriter.WriteLine("Stoppage time of " & "Cell N" & cellN & "; " & TimeSpan.FromSeconds(dstop).ToString("hh\:mm\:ss"))
                    'pathwriter.Close()
                    ApExcel.Workbooks.Open(path3)
                    ApExcel.Sheets(2).select
                    ApExcel.Cells(k, 1) = cellN
                    ApExcel.Cells(k, 2) = TimeSpan.FromSeconds(dstop).ToString("hh\:mm\:ss")
                    ApExcel.ActiveWorkbook.Close(True)
                    ApExcel.Quit()
                    k = k + 1
                End If
     
                dfe = DateTime.Now
                df1 = DateDiff(DateInterval.Second, dfR, dfe)
                df2 = DateDiff(DateInterval.Second, df, dfe)
                'pathwriter = New StreamWriter(path, True, Encoding.Unicode)
                'pathwriter.WriteLine("Cell" & cellN & " ; " & "Fronts" & " ; " & df & " ; " & TimeSpan.FromSeconds(df2).ToString("hh\:mm\:ss") & " ; " & dfR & " ; " & TimeSpan.FromSeconds(df1).ToString("hh\:mm\:ss"))
                'pathwriter.Close()
                ApExcel.Workbooks.Open(path3)
                ApExcel.Sheets(1).select
                ApExcel.Cells(i, 1) = cellN
                ApExcel.Cells(i, 2) = "Fronts"
                ApExcel.Cells(i, 3) = dfe
                ApExcel.Cells(i, 4) = TimeSpan.FromSeconds(df2).ToString("hh\:mm\:ss")
                ApExcel.Cells(i, 5) = dfR
                ApExcel.Cells(i, 6) = TimeSpan.FromSeconds(df1).ToString("hh\:mm\:ss")
                i = i + 1
                ApExcel.ActiveWorkbook.Close(True)
                ApExcel.Quit()
            End If
        End Sub
     
     
        Private Sub DEMO_Load(sender As Object, e As EventArgs) Handles Me.Load
            'initialisation
            Fronts = 0
            Backs = 0
            Elem = 0
            Screws = 0
            Boxes = 0
            Wires = 0
            Poly = 0
            Wf = 0
            others = 0
            'Choix du numéro de cellule
            cellN = InputBox("please, Write a cell number")
            While cellN = ""
                cellN = InputBox("please, Write a cell number")
            End While
     
            ''chemin du fichier texte données
            'OpenFileDialog2.Filter = "Text (*.txt)|*.txt"
            'If OpenFileDialog2.ShowDialog() = Windows.Forms.DialogResult.OK Then
            '    path = OpenFileDialog2.FileName
            'Else
            '    MsgBox("No file selected, please choose one file", MsgBoxStyle.Exclamation, "No file selected")
            'End If
            'pathwriter = New StreamWriter(path, True, Encoding.Unicode)
            'pathwriter.WriteLine("Cell" & " ; " & "part" & " ; " & "Amber" & " ; " & "Amber time" & " ; " & "RED" & " ; " & "Stoppage")
            'pathwriter.Close()
            ''chemin du fichier texte temps stop total
            'OpenFileDialog3.Filter = "Text (*.txt)|*.txt"
            'If OpenFileDialog3.ShowDialog() = Windows.Forms.DialogResult.OK Then
            '    path2 = OpenFileDialog3.FileName
            'Else
            '    MsgBox("No file selected, please choose one file", MsgBoxStyle.Exclamation, "No file selected")
            'End If
     
            'chemin du fichier EXCEL DONNEES
            OpenFileDialog3.Filter = "Excel Files(.xls)|*.xls| Excel Files(.xlsx)|*.xlsx| Excel Files(*.xlsm)|*.xlsm"
            If OpenFileDialog3.ShowDialog() = Windows.Forms.DialogResult.OK Then
                path3 = OpenFileDialog3.FileName
            Else
                MsgBox("No file selected, please choose one file", MsgBoxStyle.Exclamation, "No file selected")
            End If
            ApExcel.Workbooks.Open(path3)
            ApExcel.Sheets(1).select
            ApExcel.Cells(i, 1) = "Cell Number"
            ApExcel.Cells(i, 2) = "Parts"
            ApExcel.Cells(i, 3) = "Amber"
            ApExcel.Cells(i, 4) = "Amber Time"
            ApExcel.Cells(i, 5) = "Red"
            ApExcel.Cells(i, 6) = "Out of part time"
            ApExcel.Sheets(2).select
            ApExcel.Cells(k, 1) = "Cell Number"
            ApExcel.Cells(k, 2) = "Real Stoppage time"
            i = i + 1
            k = k + 1
            ApExcel.ActiveWorkbook.Close(True)
            ApExcel.Quit()
     
        End Sub
     
        'Close excel and free the Tablet memory and processor
     
        Private Sub DEMO_Closed(sender As Object, e As EventArgs) Handles Me.Closed
            'closing excel
     
            ApExcel.Quit()
            'System.Runtime.InteropServices.Marshal.ReleaseComObject(wsExcel)
            'System.Runtime.InteropServices.Marshal.ReleaseComObject(wbExcel)
            'System.Runtime.InteropServices.Marshal.ReleaseComObject(ApExcel)
            ApExcel = Nothing
            wbExcel = Nothing
            wsExcel = Nothing
            'remove excel process which won't close
            Call KillAllExcels()
     
        End Sub
        Sub KillAllExcels()
            Dim proc As System.Diagnostics.Process
            For Each proc In System.Diagnostics.Process.GetProcessesByName("EXCEL")
                proc.Kill()
            Next
        End Sub
    End Class
     
    'setting in excel to be shared by multiple cells shareworkbook
    L'idée c'est que cette appli enregistre toutes les données dans excel : aujourd'hui j'ai réussi à la finir, mais si le fichier excel ne peut pas être partagé/utilisé en simultané, c'est mort !
    En tout cas merci pour ton coup de pouce !
    je crée un nouveau sujet pour traiter de ce problème !

  6. #6
    Membre averti
    Homme Profil pro
    IT Manager
    Inscrit en
    Janvier 2018
    Messages
    220
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : Belgique

    Informations professionnelles :
    Activité : IT Manager
    Secteur : Santé

    Informations forums :
    Inscription : Janvier 2018
    Messages : 220
    Points : 319
    Points
    319
    Par défaut
    J'ai déjà mal de tête rien qu'à lire les déclarations de variables...

    Bon, je suppose que tu es dans une entreprise...
    Et que tu as donc un réseau local...

    Essaye d'ouvrir ton fichier excel sur un poste et ensuite sur un 2e poste...
    Garantis qu'Excel va ouvrir en lecture seule le 2e....

    Toutes modifications devra être enregistrée dans une copie....
    ça ne sera jamais gérable... il faut une base de donnée.

    Comme je t'ai dis, si tu as un abonnement office365 Access sera gratos.
    Le seul coût pour tes patrons sera le temps de développement...

    J'ai une application comme ça pour mon entreprise, elle sert à faire tout ce que notre ERP central ne peut pas faire.
    VB.NET + Access... tu sais normalement tout faire avec ça !

    Mais pour un novice, ça prends un temps de dingue pour apprendre et faire les choses correctement...
    Je veux pas te faire peur, mais j'ai mis environs 1 an pour avoir suffisamment de maitrise dans visual studio et VB.NET avant de me lancer dans un vrai projet... mais j'ai tout appris seul, avec l'aide d'internet et du forum

  7. #7
    Membre à l'essai
    Homme Profil pro
    Ingénieur mécanique
    Inscrit en
    Septembre 2019
    Messages
    34
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Ingénieur mécanique
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2019
    Messages : 34
    Points : 14
    Points
    14
    Par défaut
    oui mes variables font peur mais bon, c'est pas pour rien que je met en intitulé débutant sur ce forum

    Justement, je suis dans une entreprise en Irlande et ils viennent juste de vouloir se développer sur le côté SAP ERP.
    Sauf qu'ici personne ne sait programmer et leur service informatique est "une blague" sans être méchant (ils sont inexistant et ne savent rien faire ..., du moins c'est ce qu'ils disent ...)

    En soit le coût ne leur fait pas peur.
    Je suis actuellement en stage chez eux et ils veulent rentabiliser ma présence au max.
    Et vu que j'ai développé une petite appli sous VB.net il y a quelque temps ils se sont tous dis que je savais programmer.
    Alors que j'avais galéré rien qu'a ouvrir un fichier texte et à enregistrer des trucs dessus.

    Si aujourd'hui j'ai réussi à faire ce programme c'est en très grande partie grâce aux discussions sur ce forum des uns des autres, ton aide et aux cours en ligne.
    En soit je pense avoir progressé depuis mes débuts. Mais tu as raison, pour faire un truc correct en Base de donnée, 3 jours c'est plus que Light.

    Quoi qu'il en soit même si c'est pas fini, je tiens à partir en laissant au moins un début de solution.

  8. #8
    Membre à l'essai
    Homme Profil pro
    Ingénieur mécanique
    Inscrit en
    Septembre 2019
    Messages
    34
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Ingénieur mécanique
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2019
    Messages : 34
    Points : 14
    Points
    14
    Par défaut
    Voici le lien de la nouvelle discussion :

    https://www.developpez.net/forums/d2...bases-donnees/

  9. #9
    Membre averti
    Homme Profil pro
    IT Manager
    Inscrit en
    Janvier 2018
    Messages
    220
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : Belgique

    Informations professionnelles :
    Activité : IT Manager
    Secteur : Santé

    Informations forums :
    Inscription : Janvier 2018
    Messages : 220
    Points : 319
    Points
    319
    Par défaut
    Citation Envoyé par Heorhelm Voir le message
    Quoi qu'il en soit même si c'est pas fini, je tiens à partir en laissant au moins un début de solution.
    Alors là t'es dans la merde...
    Tu vas devoir rendre un maximum de choses gérables depuis l'interface et impliquer le plus malin de l'équipe dans le code...
    Sinon quand tu seras parti il ne sauront rien faire.

    Çà demande quand même déjà un bon niveau de connaissance je pense.

    Combien de temps tu as pour le projet ?

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [XL-2010] Problème disparition de commentaires avec fichier partagé excel
    Par Ursule court dans le forum Excel
    Réponses: 9
    Dernier message: 11/01/2023, 13h06
  2. [WD14] Sauvegarde fichier excel en mode partagé
    Par pasla dans le forum WinDev
    Réponses: 2
    Dernier message: 28/03/2013, 18h03
  3. [XL-2003] Fichier partagé Excel
    Par number8326200 dans le forum Excel
    Réponses: 1
    Dernier message: 08/11/2011, 17h17
  4. [XL-2003] Disparition toutes lignes feuille excel fichier partage
    Par atreide1971 dans le forum Excel
    Réponses: 0
    Dernier message: 20/04/2011, 10h16
  5. acces fichier excel sur disque partagé ?
    Par Cokate dans le forum C#
    Réponses: 9
    Dernier message: 14/08/2008, 09h12

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo