|
Bimbingan -
Pemrograman
|
|
Jumat, 12 September 2008 15:51 |
|
Kode berikut ini adalah Prosedur/Fungsi untuk menyimpan data dari ListView ke Microsoft Excel 97-2003 (xls format) dari Visual Basic 6.0 Sebelum menggunakan kode ini reference Microsoft Excel Object Library project harus di set aktif
Contoh: Call pFuncGenerateExcel (lvwMain, "C:\report.xls") Public Sub pFuncGenerateExcel(ByRef objListview As ListView, strOutputPath As String) Dim xlApp As Object Dim xlBook As Workbook Dim xlsheet As Object Dim i As Integer Dim s As String Dim lst As ListItem Dim lst1 As ListSubItem Dim row As Integer Dim col As Integer Set xlApp = New Excel.Application Set xlBook = xlApp.Workbooks.Add Set xlsheet = xlBook.Worksheets.Item(1) row = 1 col = 1 For i = 1 To objListview.ColumnHeaders.Count xlsheet.Cells(row, col) = objListview.ColumnHeaders(i) col = col + 1 Next col = 1 row = row + 1 For Each lst In objListview.ListItems col = 1 xlsheet.Cells(row, col) = lst.Text col = col + 1 For Each lst1 In lst.ListSubItems xlsheet.Cells(row, col) = lst1.Text col = col + 1 Next row = row + 1 Next xlBook.Close savechanges:=True, FileName:="" & strOutputPath & "" xlApp.Quit End Sub Sumber : http://www.originalpinoy.com/2008/06/export-listview-control-to-microsoft.html
|
Comments
sangat berguna.....
untuk memanggilnya copy Call pFuncGenerateEx cel (lvwMain, "C:\report.xls") di salah satu tombol program aplikasi yang anda buat.
perhatikan/samakan name listview di program aplikasi anda dengan code yang dicopy dari web ini.
ada ide lain ga???
Thanks..
War Prince
RSS feed for comments to this post