|
|
Metode dan Algoritma | Membuat Laporan Report Excel Macro VBA dengan VB.NET . Anda bisa melakukan konsultasi tentang Membuat Laporan Report Excel Macro VBA dengan VB.NET melalui form di samping kanan !!!
Report Excel
Report yang dibuat menggunakan Crystal Report kadangkala dirasa tidak flexible, karena pengguna kebanyakan lebih familiar dengan Microsoft Office, Word atau Excel. Pengguna ingin report mereka langsung terbentuk dalam format Microsoft Excel sehingga dapat diubah-ubah setiap waktu sesuai kebutuhan dan memiliki bentuk yang tepat seperti yang mereka inginkan.
Untuk membuat Report menggunakan Microsoft Excel, program yang dibuat harus dapat memanggil dan mengendalikan Microsoft Excel. Untuk melakukan hal ini program harus diberi tambahan Reference Library Microsoft Excel maupun Microsoft Office, caranya klik menu Project – Add Reference…
Setelah muncul Dialog Add Reference, pilih library Microsoft Excel Object Library dan Microsoft Office Object Library, pilih versi yang paling baru. Klik OK.
Setelah Reference ditambahkan dapat dimulai penulisan kode program. Pada bagian teratas (imports), ketikkan Imports Excel, apabila tidak ada ketikkan Imports excel = Microsoft.Office.Interop.Excel. Kemudian kode program untuk memanggil dan mengendalikan Microsoft Excel dapat dicoba dan dilihat pada fasilitas Macro Microsoft Excel (VBA / Visual Basic Application), kode program selengkapnya di bawah ini :
Imports System.IO
Imports Excel
'Imports excel = Microsoft.Office.Interop.Excel
Private Sub bExcel_Click(ByValsender As System.Object, ByVal e AsSystem.EventArgs) Handles bExcel.Click
Dim xlApp AsExcel.Application
DimxlWorkbook As Excel.Workbook
DimxlWorksheet As Excel.Worksheet
DimmisValue As Object= System.Reflection.Missing.Value
xlApp = NewExcel.Application
'xlWorkbook = xlApp.Workbooks.Open("c:\Data.xls", misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue)
xlWorkbook = xlApp.Workbooks.Add(misValue)
xlWorksheet = xlWorkbook.Sheets("Sheet1")
xlWorksheet.Columns("A:A").ColumnWidth = 3.86
xlWorksheet.Columns("B:B").ColumnWidth = 22.29
xlWorksheet.Columns("C:C").ColumnWidth = 28.86
xlWorksheet.Columns("D:D").ColumnWidth = 16.71
xlWorksheet.Range("C3").FormulaR1C1 = "Contact List"
WithxlWorksheet.Range("C3").Characters(Start:=1, Length:=12).Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 14
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = Excel.XlUnderlineStyle.xlUnderlineStyleNone
.ColorIndex = Excel.XlColorIndex.xlColorIndexAutomatic
End With
xlWorksheet.Range("B5").FormulaR1C1 = "Name"
xlWorksheet.Range("C5").FormulaR1C1 = "Address"
xlWorksheet.Range("D5").FormulaR1C1 = "Phone"
WithxlWorksheet.Range("B5:D5").Interior
.ColorIndex = 15
.Pattern = Excel.XlPattern.xlPatternSolid
.PatternColorIndex = Excel.XlColorIndex.xlColorIndexAutomatic
End With
Dim i As Integer
For i = 0 To (bs.Count - 1)
xlWorksheet.Range("B" & (i + 6).ToString).FormulaR1C1 = bs.Item(i)("name").ToString
xlWorksheet.Range("C" & (i + 6).ToString).FormulaR1C1 = bs.Item(i)("address").ToString
xlWorksheet.Range("D" & (i + 6).ToString).FormulaR1C1 = bs.Item(i)("phone").ToString
Next
WithxlWorksheet.Range("B5:D" & (bs.Count + 5).ToString).Borders(XlBordersIndex.xlEdgeLeft)
.LineStyle = XlLineStyle.xlContinuous
.Weight = XlBorderWeight.xlThin
.ColorIndex = XlColorIndex.xlColorIndexAutomatic
End With
With xlWorksheet.Range("B5:D"& (bs.Count + 5).ToString).Borders(XlBordersIndex.xlEdgeRight)
.LineStyle = XlLineStyle.xlContinuous
.Weight = XlBorderWeight.xlThin
.ColorIndex = XlColorIndex.xlColorIndexAutomatic
End With
WithxlWorksheet.Range("B5:D" & (bs.Count + 5).ToString).Borders(XlBordersIndex.xlEdgeTop)
.LineStyle = XlLineStyle.xlContinuous
.Weight = XlBorderWeight.xlThin
.ColorIndex = XlColorIndex.xlColorIndexAutomatic
End With
WithxlWorksheet.Range("B5:D" & (bs.Count + 5).ToString).Borders(XlBordersIndex.xlEdgeBottom)
.LineStyle = XlLineStyle.xlContinuous
.Weight = XlBorderWeight.xlThin
.ColorIndex = XlColorIndex.xlColorIndexAutomatic
End With
WithxlWorksheet.Range("B5:D" & (bs.Count + 5).ToString).Borders(XlBordersIndex.xlInsideHorizontal)
.LineStyle = XlLineStyle.xlContinuous
.Weight = XlBorderWeight.xlThin
.ColorIndex = XlColorIndex.xlColorIndexAutomatic
End With
WithxlWorksheet.Range("B5:D" & (bs.Count + 5).ToString).Borders(XlBordersIndex.xlInsideVertical)
.LineStyle = XlLineStyle.xlContinuous
.Weight = XlBorderWeight.xlThin
.ColorIndex = XlColorIndex.xlColorIndexAutomatic
End With
xlApp.Visible = True
'xlWorkbook.Save()
Try
xlWorksheet.SaveAs(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) & "\Report.xls")
Catchex As Exception
MsgBox("Report Masih Terbuka", MsgBoxStyle.Exclamation OrMsgBoxStyle.OkOnly, "Konfirmasi")
End Try
'xlWorkbook.Close()
'xlApp.Quit()
End Sub
Klik menu Debug – Start Debugging (F5) untuk menjalankan program, kemudian klik Tombol untuk mencoba penggunaan Microsoft Excel dari kode program Visual Basic.NET
Microsoft Excel akan dipanggil dan ditulisi report di dalamnya sesuai isi database dan dengan format / style sesuai kode program yang dituliskan. Document Excel tersebut secara otomatis juga akan tersimpan pada file Report.xls.
ActionScript AS3 ASP.NET AJAX C / C++ C# Clipper COBOL ColdFusion DataFlex Delphi Emacs Lisp Fortran FoxPro Java J2ME JavaScript JScript Lingo MATLAB Perl PHP PostScript Python SQL VBScript Visual Basic 6.0 Visual Basic .NET Flash MySQL Oracle Android
Related Post :

Judul: Membuat Laporan Report Excel Macro VBA dengan VB.NET
Rating: 100% based on 99998 ratings. 5 user reviews.
Ditulis Oleh hank2
Rating: 100% based on 99998 ratings. 5 user reviews.
Ditulis Oleh hank2
Anda sedang membaca artikel tentang
Membuat Laporan Report Excel Macro VBA dengan VB.NET, Semoga artikel tentang Membuat Laporan Report Excel Macro VBA dengan VB.NET ini sangat bermanfaat bagi teman-teman semua, jangan lupa untuk mengunjungi lagi melalui link
Membuat Laporan Report Excel Macro VBA dengan VB.NET.

{ 0 komentar... Views All / Send Comment! }
Posting Komentar