Hi, Teman-teman setelah memposting source code membaca file excel dengan vb.net tidak abdol rasanya jika tidak membuat tutorialnya. Karena mungkin ada sebagian agan-agan yang ingin belajar bagaimana cara membuat program itu..
jadi silahkan ikuti tutorial dibawah ini :
- Buat Sebuah Projek menggunakan visual basic 2008.
- Kemudian design form anda menjadi seperti dibawah ini .
Design Form - Kemudian klik menu Project >> Add Reference... dan pilih tab COM. seleksi dan pilih komponen Microsoft Excel 12.0 Object Library
memilih referensi - Kemudian ketikkan program dibawah ini
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
Dim app As New Excel.Application
Dim workwheet As Excel.Worksheet
Dim workbook As Excel.Workbook
Dim OldCulture = System.Threading.Thread.CurrentThread.CurrentCulture
Dim newCulture = New System.Globalization.CultureInfo(app.LanguageSettings.LanguageID(Microsoft.Office.Core.MsoAppLanguageID.msoLanguageIDUI))
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
System.Threading.Thread.CurrentThread.CurrentCulture = newCulture
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
workbook = app.Workbooks.Open(Application.StartupPath & "\mahasiswa.xlsx")
workwheet = workbook.Sheets.Item(1)
TextBox1.Text = workwheet.Cells(2, 1).value
TextBox2.Text = workwheet.Cells(2, 2).value
TextBox3.Text = workwheet.Cells(2, 3).value
TextBox4.Text = workwheet.Cells(2, 4).value
app.ActiveWorkbook.Close(False, Application.StartupPath & "\mahasiswa.xlsx")
app.Quit()
End Sub
End Class
Public Class Form1
Dim app As New Excel.Application
Dim workwheet As Excel.Worksheet
Dim workbook As Excel.Workbook
Dim OldCulture = System.Threading.Thread.CurrentThread.CurrentCulture
Dim newCulture = New System.Globalization.CultureInfo(app.LanguageSettings.LanguageID(Microsoft.Office.Core.MsoAppLanguageID.msoLanguageIDUI))
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
System.Threading.Thread.CurrentThread.CurrentCulture = newCulture
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
workbook = app.Workbooks.Open(Application.StartupPath & "\mahasiswa.xlsx")
workwheet = workbook.Sheets.Item(1)
TextBox1.Text = workwheet.Cells(2, 1).value
TextBox2.Text = workwheet.Cells(2, 2).value
TextBox3.Text = workwheet.Cells(2, 3).value
TextBox4.Text = workwheet.Cells(2, 4).value
app.ActiveWorkbook.Close(False, Application.StartupPath & "\mahasiswa.xlsx")
app.Quit()
End Sub
End Class
Bagaimana cara nya search sheet excel nya melalui combo box? bisa tolong agan2...
ReplyDelete