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
|
'ouvre la feuille 1 de l'application mais la laisse invisible
AppExcel = New OXL.Application
xlWorkbook = AppExcel.Workbooks.Open(appPath & "\monClasseur.xls")
xlWorkSheetOne = CType(xlWorkbook.Worksheets(1), Microsoft.Office.Interop.Excel.Worksheet)
AppExcel.Visible = False
'chargement des data en Textbox
Dim rng As OXL.Range = Nothing
rng = CType(Me.xlWorkSheetOne.Cells(10, 7), Microsoft.Office.Interop.Excel.Range)
Me.txtNOM.Text = CType(rng.Value, String)
rng = CType(Me.xlWorkSheetOne.Cells(10, 8), Microsoft.Office.Interop.Excel.Range)
Me.txtPRENOM.Text = CType(rng.Value, String)
rng = CType(Me.xlWorkSheetOne.Cells(10, 9), Microsoft.Office.Interop.Excel.Range)
Me.TxtNAISSANCE.Text = CType(rng.Value, String)
rng = CType(Me.xlWorkSheetOne.Cells(16, 2), Microsoft.Office.Interop.Excel.Range)
Me.S.Text = CType(rng.Value, String)
rng = CType(Me.xlWorkSheetOne.Cells(16, 3), Microsoft.Office.Interop.Excel.Range)
Me.C.Text = CType(rng.Value, String)
rng = CType(Me.xlWorkSheetOne.Cells(16, 4), Microsoft.Office.Interop.Excel.Range)
Me.AXE.Text = CType(rng.Value, String)
rng = CType(Me.xlWorkSheetOne.Cells(16, 8), Microsoft.Office.Interop.Excel.Range)
Me.SC.Text = CType(rng.Value, String)
rng = CType(Me.xlWorkSheetOne.Cells(16, 9), Microsoft.Office.Interop.Excel.Range)
Me.CC.Text = CType(rng.Value, String)
rng = CType(Me.xlWorkSheetOne.Cells(16, 10), Microsoft.Office.Interop.Excel.Range)
Me.AC.Text = CType(rng.Value, String)
.
.
.
MessageBox.Show("Data loaded in the form")
CloseAppExcel()
End Sub
Private Sub CloseAppExcel()
'procedure de fermeture du fichier excel
If xlWorkSheetOne IsNot Nothing Then
xlWorkSheetOne = Nothing
End If
If xlWorkSheetTwo IsNot Nothing Then
xlWorkSheetTwo = Nothing
End If
If xlWorkbook IsNot Nothing Then
xlWorkbook = Nothing
End If
If AppExcel IsNot Nothing Then
AppExcel.Quit()
AppExcel = Nothing
End If
End Sub |
Partager