Beberapa Fungsi dari listview sudah saya tampilkan dipostingan sebelumnya, sekarang saya menemukan hal yang baru buat saya, yaitu Export data yang ada listview ke Excel, mungkin hal ini penting gak penting tetapi akan sangat dibutuhkan apabila sobat mau cross check hasil dari input user tanpa harus buka program aplikasinya.
“Disc space computer saya sudah penuh, tak simpan disini saja”
Dari pada panjang lebar ---> Berikut
Source Codenya :
Sub Export()On Error Resume NextScreen.MousePointer = vbHourglassDim Rfs As IntegerDim LstFld As IntegerDim exc As New Excel.ApplicationDim wb As Excel.WorkbookDim ws As Excel.WorksheetDim k As IntegerDim CLms As IntegerDim no As Integer'On Error GoTo 1Set wb = exc.Workbooks.AddSet ws = wb.Worksheets(1)LstFld = 9 ‘Jumlah Collumnws.Cells.Clearexc.Visible = True '<---- Merubah dari “ False” Export ke excel data'On Error GoTo 1For CLms = 1 To LstFldws.Cells(1, CLms).Font.Bold = True '<-- Boldws.Cells(1, CLms) = Me.Listview1.ColumnHeaders(CLms).Text '<---Menambahkan ListViewer column headers ke XL Sheetws.Cells(1, CLms).Font.Color = &H8000& '<--- Warna Hijauws.Cells(1, CLms).Interior.Color = vbGreenNext CLms‘Menampilkan criteria selectionws.Cells(2, 2) = "Selection : ******************"ws.Cells(3, 2) = "Tanggal : ***" & Format(D1, "dd/mm/yyyy") & " --- s/d --- " & Format(D2, "dd/mm/yyyy")ws.Cells(4, 2) = "Kelompok : ***" & Combo1.Text & ",----- Item --- : " & T1.Text & " - " & Label5.Captionws.Cells(2, 2).Font.Color = &H808000ws.Cells(3, 2).Font.Color = &H808000ws.Cells(4, 2).Font.Color = &H808000Dim flds As IntegerDim flds2 As IntegerDim strFlds As Stringflds2 = LstFldFor i = 1 To TraceItem.ListItems.CountstrFlds = ""strFlds = Me.TraceItem.ListItems(i).Textws.Cells(i + 5, 1) = strFlds '<--- data export ke Excel sheetFor flds = 1 To flds2strFlds = ""strFlds = Me.TraceItem.ListItems(i).ListSubItems(flds).Textws.Cells(i + 5, flds + 1) = strFlds '<--- data export to Excel sheetNext fldsNext i'For CLms = 1 To LstFldws.Columns(1).AutoFit '<---Autofilt data on XL sheet'Next CLms‘Menampilkan data non listviewws.Cells(Me. Listview1.ListItems.Count + 8, 1) = "" '<---Bemberikan jarak pada baris terakhirws.Cells(Me. Listview1.ListItems.Count + 9, 2) = "Software by: Agoes Priyanto bocah Sragen"ws.Cells(Me. Listview1.ListItems.Count + 10, 2) = "Export Data tanggal" & " " & Format(Now, "dd.mm.yyyy")Dim clms1 As IntegerFor clms1 = 1 To 9ws.Cells(Me. Listview1.ListItems.Count + 8, 2).Font.Bold = True '<-- Boldws.Cells(Me. Listview1.ListItems.Count + 8, 2).Font.Color = &H808000 '<--- Green Colorws.Cells(Me. Listview1.ListItems.Count + 9, 2).Font.Bold = Truews.Cells(Me. Listview1.ListItems.Count + 9, 2).Font.Color = &H808000 '<--- Green Colorws.Cells(Me. Listview1.ListItems.Count + 10, 2).Font.Bold = Truews.Cells(Me. Listview1.ListItems.Count + 10, 2).Font.Color = &H808000 '<--- Green ColorNext clms1ws.Name = Me. Listview1.Name '<----Nama Sheetexc.Visible = True '<--- Membuka Excel sheet setelah ExportSet wb = Nothing ‘Mengembalikan ke nilai awalSet ws = Nothing ‘Mengembalikan ke nilai awal'1:'MsgBox Err.Description, vbCritical, "Error " & Err.NumberScreen.MousePointer = vbDefaultExit SubEnd Sub
Hasil dari Export seperti gambar :
Semoga bermanfaat
Link Download Contoh Project Disini (Office Excel)
Link Download Contoh Project Disini (Spreadsheet 2012)
Wassalamualaikum wr.wb
Link Download Contoh project, [.dll],[.ocx]
Tweet |
6 komentar:
keren nih gan info nya terimakasih jangan lupa mampir yah di
http://maribelajarvisualbasic.blogspot.com/
thank's
Tank...gan...
OK...kunbal
Siap...
thanks gan
walaupun belom dicoba, tapi layak mendapatkan jempol
@adienz...
Jempol kaki...Tpi...mambu...
heheheee....canda masbro...
Suwun yea...
siip, bos....tapi ada yang cara export dari datagrid ga bos...
khususnya cara membuat linestyle dan noUrut otomatis sesuai banyaknya yg di tampilkan grid...please...email kawan_q@yahoo.co.id
Gan...ada cara export datagrid ke excel
Posting Komentar
Say: Berkomentarlah dengan baik dan sopan...dan jangan gunakan SPAM untuk blog ini...Terima kasih [by.admin]