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
|
OpenFileDialog1.InitialDirectory = "C:\" 'Adresse initiale
OpenFileDialog1.Filter = "Fichier excell (*.xls)|*.xls"
OpenFileDialog1.ShowDialog()
TextBox1.Text = OpenFileDialog1.FileName.ToString()
'**************************************************************************'
'Charge le fichier et recup les infos
Dim Fichier As String
Dim Rst As ADODB.Recordset
'Définit le classeur fermé servant de base de données
Fichier = OpenFileDialog1.FileName.ToString()
'Nom de la feuille dans le classeur fermé
'Définition des variables de saisie
Dim Cellules As String = "A1:B1000"
Dim test(1000, 2) As Object
'Definition des sources
Dim Source As ADODB.Connection
Source = New ADODB.Connection
Source.Open("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Fichier & ";Extended Properties=""Excel 8.0;HDR=No;"";")
Dim ADOCommand As ADODB.Command
ADOCommand = New ADODB.Command
With ADOCommand
.ActiveConnection = Source
.CommandText = "SELECT * FROM [Feuil1$" & Cellules & "] WHERE 1=1"
End With
'Execution de la commande
Rst = New ADODB.Recordset
Rst.Open(ADOCommand, , ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)
'Récupération des données
Rst.MoveFirst()
test = Rst.GetRows(-1, 0, )
'Fermeture du fichier
Rst.Close()
Source.Close()
Source = Nothing
Rst = Nothing
ADOCommand = Nothing
'**************************************************************************'
'MessageBox.Show(test.Length)
Dim val As Integer = test.Length / 2 'Division par 2 car la longueur prends tous les éléments
For i As Integer = 0 To val - 1 'Et que j'ai deux colonnes
ListBox1.Items.Add(test(0, i))
ListBox2.Items.Add(test(1, i))
Next |