Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. Private Sub ExcelExtract(ByVal chemin As String)
  2.  
  3. ProgressBarX1.Value = 0
  4.  
  5. 'Excel
  6.  
  7. Dim xlApp As Application
  8. Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook
  9. Dim xl1 As Microsoft.Office.Interop.Excel.Worksheet
  10.  
  11. 'Code
  12. xlApp = New Microsoft.Office.Interop.Excel.Application
  13.  
  14. xlWorkBook = xlApp.Workbooks.Open(chemin)
  15. xl1 = xlWorkBook.Worksheets(1)
  16.  
  17. For i As Integer = firstLigne To lastLigne 'Lignes du tableau
  18. ProgressBarX1.Value = i * 100 / (lastLigne - firstLigne)
  19. LabelX2.Text = "" & Math.Round((i * 100 / (lastLigne - firstLigne)), 0) & " %"
  20. If xl1.Cells(i, columnMachines).value <> "" Then
  21. nomMachine = xl1.Cells(i, columnMachines).value
  22. For j As Integer = 0 To 2
  23. For col As Integer = firstColumn To lastColumn 'Colonnes du tableau
  24. If xl1.Cells(i + j, col).Interior.colorindex = 48 And xl1.Cells(i + j, col).value Is Nothing Then
  25. 'Trouver le mois
  26. Dim words As String = xl1.Cells(ligneMois, col).MergeArea.Address.ToString()
  27. Dim split As String() = words.Split(New [Char]() {":"c, CChar(vbTab)})
  28. ExecuteSql("INSERT INTO poste(nomPoste, nomMachine,Equipe,date)" & _
  29. "values('" & xl1.Cells(i, columnPostes).value & "'," & _
  30. "'" & nomMachine & "'," & _
  31. "'" & xl1.Cells(i + j, columnEquipe).value & "'," & _
  32. "'" & xl1.Cells(ligneJour, col).value.ToString() & " " & xl1.Range("" & split(0) & "").Value & " 2014')")
  33. End If
  34. Next
  35. Next
  36. ElseIf xl1.Cells(i, columnPostes).value <> "" Then
  37. For j As Integer = 0 To 2
  38. For col As Integer = firstColumn To lastColumn 'Colonnes du tableau
  39. If xl1.Cells(i + j, col).Interior.colorindex = 48 And xl1.Cells(i + j, col).value Is Nothing Then
  40. Dim words As String = xl1.Cells(ligneMois, col).MergeArea.Address.ToString()
  41. Dim split As String() = words.Split(New [Char]() {":"c, CChar(vbTab)})
  42. ExecuteSql("INSERT INTO poste(nomPoste, nomMachine,Equipe,date)" & _
  43. "values('" & xl1.Cells(i, columnPostes).value & "'," & _
  44. "'" & nomMachine & "'," & _
  45. "'" & xl1.Cells(i + j, columnEquipe).value & "'," & _
  46. "'" & xl1.Cells(ligneJour, col).value.ToString() & " " & xl1.Range("" & split(0) & "").Value & " 2014')")
  47. End If
  48. Next
  49. Next
  50. Else
  51. End If
  52. Next
  53.  
  54. 'Active app could change before this runs
  55. xlWorkBook.Close(False)
  56. xlWorkBook = Nothing
  57.  
  58. xlApp.Quit()
  59. xlApp = Nothing
  60.  
  61. System.GC.Collect()
  62. System.GC.WaitForPendingFinalizers()
  63. System.GC.Collect()
  64. System.GC.WaitForPendingFinalizers()
  65.  
  66. ProgressBarX1.Value = 100
  67. ProgressBarX2.Visible = True
  68. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement