pb Excel to datawindow

string ls_execlpath, docname[]

int li_i=1
int li_rtn

int li_excelrow, li_dwrow, li_dwcol
string ls_path
any la_excelcell


OleObject Ole_excel, Ole_workbook

ls_path = GetCurrentDirectory()
ls_path=ls_path+"/.."

Ole_excel = create OleObject
Ole_excel.connecttonewobject( "excel.Application")

//Ole_excel.workbooks.add()


li_rtn = GetFileOpenName("请选择导入Excel文件", ls_execlpath, docname[], "xls", &
   + "Excel Files (*.xls),*.xls,", ls_path, 18)

if  li_rtn=0 then
 return
end if

Ole_excel.workbooks.open(ls_execlpath)
ole_workbook=ole_excel.worksheets(1)


li_excelrow=2 //从第几行开始
li_dwcol = integer(dw_1.describe("datawindow.column.count"))

do

 la_excelcell = ole_workbook.cells(li_excelrow,1).value
 if trim(string(la_excelcell)) =''   or isnull(la_excelcell) then
  exit;
 end if
 
 li_dwrow=dw_1.insertrow( 0)
 
 for li_i=1 to li_dwcol
  dw_1.setitem(li_dwrow, li_i, trim(string(ole_workbook.cells(li_excelrow,li_i).value)))
 next
    li_excelrow=li_excelrow+1
 
loop while true

ole_excel.quit()
ole_excel.disconnectobject( )
 destroy ole_excel
 destroy ole_workbook

你可能感兴趣的:(pb Excel to datawindow)