Selamat Pagi (nulis nya pagi2 ceritanya). Pagi ini Rani lagi pengen nulis perihal bagaimana cara membaca file excel memakai VB.NET. Langsung aja yah....
Ini isi file excel yang akan kita gunakan, Rani nyimpen nya di D:\karyawan.xlsx.
Pertama kita akan menyertakan referensi excel dengan cara klik sajian Project -> Add Reference...
Pilih Microsoft.Office.Interop.Excel lalu klik OK.
UI nya simple aja form sama button aja.
Code:
Imports Microsoft.Office.Interop
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
xlApp = New Excel.ApplicationClass
xlWorkBook = xlApp.Workbooks.Open("D:\karyawan.xlsx")
xlWorkSheet = xlWorkBook.Worksheets("sheet1")
'display the cells value B2
MsgBox(xlWorkSheet.Cells(2, 2).value)
xlWorkBook.Close()
xlApp.Quit()
End Sub
End Class
Lets run!!!
Happy Coding!!!
Rani mo ke sabuga dahulu heuheu c u....
Update!!! Gimana klo pengen tahu sheet apa aja yang ada di dalam file excel tersebut? Contoh step by step nya disini yaah....
Click here if you like this article.
Sumber http://rani-irsan.blogspot.com
EmoticonEmoticon