Jan 15, 2012

Import excel into datawindow

Tested in Microsoft Ofice Excel 2003

oleobject excel
long ll_hasil,ll_return,ll_count
boolean lb_cek
excel = create oleobject;
//connect to office application
ll_return = excel.connecttonewobject("excel.application")
if ll_return <> 0 then
messagebox('Peringatan','Tidak dapat mengeksekusi MS.Excel!',exclamation!)
destroy excel
return 0
end if
//open file excel (you can make this string as variable)
excel.workbooks.open( "c:\xls\contoh file excel.xls" )
excel.application.visible = false
excel.windowstate = 2
//cek rows in excel sheet with return value copy
lb_cek = excel.worksheets(3).activate
excel.worksheets(3).range("A2:Z5000").Copy //column range in excel files
ll_count = dw_1.importclipboard()
if ll_count <= 0 then
messagebox('Informasi','Data tidak ditemukan!')
end if
excel.worksheets(3).range("A10000:A10000").Copy
excel.application.quit
excel.disconnectobject()
destroy excel;

How it works?
This script open excel file, read cell and copy to clipboard. And then insert into datawindow.
You also import multiple sheet or multiple excel file.
Cheers..

No comments:

Post a Comment

Are legacy 4GL applications keeping you from embracing modern technologies?

As the competitive advantages offered by cloud, mobile, and other new technologies become more apparent, the decision to migrate legacy 4GL ...