Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub ExcelExtract(ByVal chemin As String)
- ProgressBarX1.Value = 0
- 'Excel
- Dim xlApp As Application
- Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook
- Dim xl1 As Microsoft.Office.Interop.Excel.Worksheet
- 'Code
- xlApp = New Microsoft.Office.Interop.Excel.Application
- xlWorkBook = xlApp.Workbooks.Open(chemin)
- xl1 = xlWorkBook.Worksheets(1)
- For i As Integer = firstLigne To lastLigne 'Lignes du tableau
- ProgressBarX1.Value = i * 100 / (lastLigne - firstLigne)
- LabelX2.Text = "" & Math.Round((i * 100 / (lastLigne - firstLigne)), 0) & " %"
- If xl1.Cells(i, columnMachines).value <> "" Then
- nomMachine = xl1.Cells(i, columnMachines).value
- For j As Integer = 0 To 2
- For col As Integer = firstColumn To lastColumn 'Colonnes du tableau
- If xl1.Cells(i + j, col).Interior.colorindex = 48 And xl1.Cells(i + j, col).value Is Nothing Then
- 'Trouver le mois
- Dim words As String = xl1.Cells(ligneMois, col).MergeArea.Address.ToString()
- Dim split As String() = words.Split(New [Char]() {":"c, CChar(vbTab)})
- ExecuteSql("INSERT INTO poste(nomPoste, nomMachine,Equipe,date)" & _
- "values('" & xl1.Cells(i, columnPostes).value & "'," & _
- "'" & nomMachine & "'," & _
- "'" & xl1.Cells(i + j, columnEquipe).value & "'," & _
- "'" & xl1.Cells(ligneJour, col).value.ToString() & " " & xl1.Range("" & split(0) & "").Value & " 2014')")
- End If
- Next
- Next
- ElseIf xl1.Cells(i, columnPostes).value <> "" Then
- For j As Integer = 0 To 2
- For col As Integer = firstColumn To lastColumn 'Colonnes du tableau
- If xl1.Cells(i + j, col).Interior.colorindex = 48 And xl1.Cells(i + j, col).value Is Nothing Then
- Dim words As String = xl1.Cells(ligneMois, col).MergeArea.Address.ToString()
- Dim split As String() = words.Split(New [Char]() {":"c, CChar(vbTab)})
- ExecuteSql("INSERT INTO poste(nomPoste, nomMachine,Equipe,date)" & _
- "values('" & xl1.Cells(i, columnPostes).value & "'," & _
- "'" & nomMachine & "'," & _
- "'" & xl1.Cells(i + j, columnEquipe).value & "'," & _
- "'" & xl1.Cells(ligneJour, col).value.ToString() & " " & xl1.Range("" & split(0) & "").Value & " 2014')")
- End If
- Next
- Next
- Else
- End If
- Next
- 'Active app could change before this runs
- xlWorkBook.Close(False)
- xlWorkBook = Nothing
- xlApp.Quit()
- xlApp = Nothing
- System.GC.Collect()
- System.GC.WaitForPendingFinalizers()
- System.GC.Collect()
- System.GC.WaitForPendingFinalizers()
- ProgressBarX1.Value = 100
- ProgressBarX2.Visible = True
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement