Here is a sample code to read excel data
OLEObject xlapp, xlsub
String ls_filename = 'one.xls'
Long ll_sheet, ll_max_rows, ll_max_columns, ll_start, ll_end
ll_start = 1
ll_end = 500 // To read 500 rows
// Create OLE
xlApp = Create OLEObject
ll_ret = xlApp.ConnectToNewObject( "Excel.Application" )
If ll_ret < 0 then
Return
End If
try
// Open Excel file
xlApp.Application.Workbooks.Open(ls_filename)
// Open Active sheet
ll_sheet = 1
xlsub = xlapp.Application.ActiveWorkbook.Worksheets[ll_sheet]
ll_max_rows = Xlsub.UsedRange.Rows.Count
ll_max_columns = Xlsub.UsedRange.Columns.Count
If ll_start = 1 Then ll_start = 2
dw_1.SetReDraw(False)
For ll_cnt = ll_start to ll_end
ll_row = tab_1.tabpage_1.dw_1.InsertRow(0)
ll_inc ++
dw_1.SetItem(ll_row, 'field1', Mid(Trim(String(xlsub.cells[ll_cnt, 1].value)),1,20))
dw_1.SetItem(ll_row, 'field2', Mid(Trim(String(xlsub.cells[ll_cnt, 2].value)),1,10))
dw_1.SetItem(ll_row, 'field3', Mid(Trim(String(xlsub.cells[ll_cnt, 3].value)),1,3))
Yield()
Next
dw_1.SetReDraw(True)
CATCH ( runtimeerror lo_rte)
MessageBox('Error', "MS Excel api runtime error")
FINALLY
// Quit
XlApp.Workbooks.close()
xlapp.quit()
xlapp.DisconnectObject()
tab_1.tabpage_1.dw_1.SetReDraw(True)
Destroy xlsub
Destroy xlapp
GarbageCollect()
END TRY
HTH
Happiness Always
BKR Sivaprakash
Btw, do you see any limitations on this 'clipboard' copy method? There seems to a limit in the no. of rows that one can process by opening the excel file through OLE object. Reading 25000 rows isn't a problem, and above that the software terminates. My application is 32bit.
I am not aware of any limitation on the no. of rows. For what I'm using it for, we will typically have maybe a hundred or less records and 3 columns to copy and paste. My application is 32 bit as well.
Winnie