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
| Private Sub ButtonAltead2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonAltead2.Click
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet
Try
xlApp = New Microsoft.Office.Interop.Excel.Application
xlWorkSheet = New Microsoft.Office.Interop.Excel.Worksheet
' Dim misValue As Object = System.Reflection.Missing.Value
Dim ixLine As Integer
'Ouverture de l'application
xlApp = CType(CreateObject("Excel.Application"), Microsoft.Office.Interop.Excel.Application)
'Ouverture d'un fichier Excel
xlWorkBook = xlApp.Workbooks.Open("D:\DataUser\Feuille d'heure\S1-Fiche de travail hebdomadaire.xls")
'wsExcel correspond à la première feuille du fichier
xlWorkSheet = CType(xlWorkBook.Worksheets("S1-Fiche Travail Hebdo"), Microsoft.Office.Interop.Excel.Worksheet)
xlWorkSheet.Visible = Microsoft.Office.Interop.Excel.XlSheetVisibility.xlSheetVisible
xlApp.Visible = True
Dim sfd As New SaveFileDialog
'Dim rtb As New RichTextBox
'sfd.Filter = "Excel|*.xls|Texte|*.txt|Richtext|*.rtf"
'sfd.Title = "Sauver le fichier exporter sous ?"
'sfd.FileName = "D:\DataUser\Feuille d'heure\S1-Fiche de travail hebdomadaire.xls"
'sfd.ShowDialog()
'If sfd.ShowDialog() = DialogResult.OK Then
' rtb.SaveFile(sfd.FileName, _
' RichTextBoxStreamType.PlainText)
'End If
'Dim chemin As String = "D:\DataUser\TLUC\OJDO"
'Dim result As DialogResult = sfd.ShowDialog()
'If (result = Windows.Forms.DialogResult.OK) Then
' chemin = sfd.FileName
' xlWorkSheet.SaveAs("D:\DataUser\TLUC\OJDO" & ".xlsx")
' xlApp.Application.Quit()
'End If
Dim collectionLignes As New System.Collections.Generic.List(Of Ligne)
'lecture dgv
For ixLine = 0 To DataGridAlteadHeuresSemaine.DGV.RowCount - 1
Dim DGVdate As String = CType(DataGridAlteadHeuresSemaine.DGV(1, ixLine).Value, String)
Dim DGVnumAffaire As String = CType(DataGridAlteadHeuresSemaine.DGV(2, ixLine).Value, String)
Dim DGVclient As String = CType(DataGridAlteadHeuresSemaine.DGV(3, ixLine).Value, String)
Dim DGVsite As String = CType(DataGridAlteadHeuresSemaine.DGV(4, ixLine).Value, String)
Dim DGVnbH As String = CType(DataGridAlteadHeuresSemaine.DGV(5, ixLine).Value, String)
' Dim DGVcodeActivite As String = CType(DataGridAlteadHeuresSemaine.DGV(7, ixLine).Value, String)
Dim maLigne As New Ligne(DGVdate, DGVnumAffaire, DGVclient, DGVsite, DGVnbH) 'DGVcodeActivite)
If Not maLigne.TraitementValeurs() Then
Throw New System.Exception("erreur lors du traitement des valeurs")
End If
collectionLignes.Add(maLigne)
Next
'lecture de la collection
Dim line As Ligne
Dim ixExcel As Integer = 8
Dim strFullName As String = Me.ComboBoxAlteadRessource.Text
Dim strName As String = strFullName.Split(CType(" ", Char))(0)
Dim strFirstName As String = strFullName.Split(CType(" ", Char))(1)
For Each line In collectionLignes
If line.xlsJour = "sam" Then
ElseIf line.xlsJour = "dim" Then
xlWorkSheet.Cells(ixExcel, "ab") = line.xlsHeures.ToString
End If
xlWorkSheet.Cells(ixExcel, "b") = line.xlsJour
xlWorkSheet.Cells(ixExcel, "d") = line.xlsDate.ToString
'xlWorkSheet.Cells(ixExcel, "f") = line.xlsCodeActivite
xlWorkSheet.Cells(ixExcel, "f") = line.xlsNumAffaire
xlWorkSheet.Cells(ixExcel, "k") = line.xlsClient
xlWorkSheet.Cells(ixExcel, "q") = line.xlsSite
xlWorkSheet.Cells(ixExcel, "x") = line.xlsHeures.ToString
xlWorkSheet.Cells(ixExcel, "ai") = line.xlsBrmDplcmt
xlWorkSheet.Cells(ixExcel, "af") = line.xlsDistDomChant.ToString
xlWorkSheet.Cells(3, "e") = line.xlsDate.ToString
xlWorkSheet.Cells(3, "u") = xlWorkSheet.Cells(8, "d")
xlWorkSheet.Cells(3, "o") = NumSemaine
xlWorkSheet.Cells(5, "b") = strName
xlWorkSheet.Cells(5, "k") = strFirstName
ixExcel = ixExcel + 1
Next
Catch ex As Exception
TraceErreur.Trace(ex, Me)
Me.Saisie.GestionMessage.AfficheMessage("Erreur", "Erreur lors de l'exportation excel", ContentAlignment.MiddleCenter, Me)
Finally
releaseObject(xlApp)
releaseObject(xlWorkBook)
releaseObject(xlWorkSheet)
End Try
End Sub
Private Sub releaseObject(ByVal obj As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
Catch ex As Exception
obj = Nothing
Finally
'GC.Collect()
End Try
End Sub
Private Class Ligne
Public Function TraitementValeurs() As Boolean
Try
xlsJour = Split(DGVdate, " ")(0).Substring(0, 3)
xlsDate = CDate(Split(DGVdate, " ")(1))
'xlsCodeActivite = Split(DGVcodeActivite, "-")(0)
xlsNumAffaire = DGVnumAffaire
xlsClient = DGVclient
xlsSite = DGVsite
xlsHeures = CDec(DGVnbH)
Return True
Catch ex As Exception
Return False
TraceErreur.Trace(ex, Me)
End Try
End Function
Public xlsJour As String
Public xlsDate As Date
' Public xlsCodeActivite As String
Public xlsNumAffaire As String
Public xlsClient As String
Public xlsSite As String
Public xlsHeures As Decimal
Public xlsDistDomChant As Decimal
Public xlsBrmDplcmt As String
Public DGVdate As String
Public DGVnumAffaire As String
Public DGVclient As String
Public DGVsite As String
Public DGVnbH As String
'Public DGVcodeActivite As String
Public Sub New(ByVal _DGVdate As String, ByVal _DGVnumAffaire As String, ByVal _DGVclient As String, ByVal _DGVsite As String, ByVal _DGVnbH As String) ', ByVal _DGVcodeActivite As String)
Try
Me.DGVdate = _DGVdate
Me.DGVnumAffaire = _DGVnumAffaire
Me.DGVclient = _DGVclient
Me.DGVsite = _DGVsite
Me.DGVnbH = _DGVnbH
'Me.DGVcodeActivite = _DGVcodeActivite
Catch ex As Exception
TraceErreur.Trace(ex, Me)
End Try
End Sub
End Class
End Class |
Partager