Minggu, 24 Januari 2010

Membuat Laporan dari Vfp ke bentuk Excel

Cara membuat laporan dari Vfp ke dalam bentuk Excel adalah sebagai berikut :
1. Buat tables seperti apa yang akan ditampilan di Excel nantinya
contoh pada tables_Vfp berisi Field Nip, Nama, upah,alamat
pada excel ingin menampilkan dengan urutan nip,nama,alamat,upah
SELECT nip,nama,alamat,upah from tables_Vfp into cursor tampungan

2. Copy hasil tampungan tadi ke dalam tables VFP
contoh select tampungan
copy to export_excel type xl5

3. jangan lupa ikut sertakan variable dibawah ini didalam program export ke excel

Memanggil object excel agar bisa dibaca didalam VFP
oExcel = CreateObject("Excel.Application")
oExcel.Visible = .T.
xlMedium=-4138
xlCenter=-4108
xlLeft=-4131
xlRight=-4152
xldiagonaldown= 5
xlbottom=-4107
xldiagonalup=6
xledgeleft=7
xlNone=-4142
xlcontinuous=1
xlDouble=1
xlThick=2
xlLastCell=11
xlthin=2
xlContext=-5002
xlautomatic=-4105
xledgetop=8
xledgebottom=9
xledgeright=10
xlinsidevertical=11
xlinsidehorizontal=12
xlautomatic=-4105
xlsolid=1
xlHairline=1
xlLandscape=2
xlUnderlineStyleNone=-4142
xlDown=-4121
xlUnderlineStyleSingle=2

4. Buka File hasil export ke excel
oWorkbook = oExcel.Workbooks.Open(export_excel)

agar lebar colum menyesuaikan secara otomatis
oWorkbook = oExcel.Cells.EntireColumn.AutoFit

5. Insert beberapa baris untuk judul hasil export yang diexcel
misal insert dari baris 1 samapai baris 7
oWorkbook = oExcel.Rows("1:7").Select
oWorkbook = oExcel.Rows("1:7").Insert

6. Memberi judul pada hasil export excel
misal pada A2 dikasih judul Daftar Upah
WITH oExcel.sheets(1)
.select
.Range("A2").select
.Range("A2").Value = "Daftar Upah"
ENDWITH

atau

WITH oExcel
.Range("A2").Select
.ActiveCell.FormulaR1C1 = "Daftar Upah"
endiwth

selamat mencoba dan semogga berhasil bila kesulitan bisa kontak di asharifaisal@gmail.com