Import File Excel
1. Buatlah sebuah form
2. Tambahkan sebuah button dan datagridview (ubah namanya menjadi DGV)
3. Tambahkan pula komponen openfiledialog
4. Buatlah tabel dengan excel
5. Simpan file tersebut di folder tertentu
6. Tutup file excel
7. Klik dua kali button
8. Tulis coding di bawah ini
Imports System.Data.OleDb
Public Class import_dari_excel
Dim conn As OleDbConnection
Dim da As OleDbDataAdapter
Dim ds As New DataSet
Dim cmd As OleDbCommand
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
On Error Resume Next
openfiledialog1.Filter = "(*.xls)|*.xls|(*.xlsx)|*.xlsx|All files (*.*)|*.*"
OpenFileDialog1.ShowDialog()
conn = New OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;" & _
"data source='" & OpenFileDialog1.FileName & "';Extended Properties=Excel 8.0;")
da = New OleDbDataAdapter("select * from [Sheet1$]", conn)
conn.Open()
ds.Clear()
da.Fill(ds)
DGV.DataSource = ds.Tables(0)
conn.Close()
End Sub
End Class
Tidak ada komentar:
Posting Komentar