首页 > 代码库 > excel导入pb

excel导入pb

 

string ls_excelpath,docname
integer li_rtn
li_rtn = GetFileOpenName("Select File", ls_excelpath, docname, "XLS", + "Text Files (*.XLS),*.XLS," + "Doc Files (*.XLS),*.XLS")
OleObject oXls,oSheet,oBook
integer ll_Xls
oXls=CREATE OleObject
ll_Xls=oXls.ConnectToObject(‘‘,‘excel.application‘)
Long ll_Row,curRow
Decimal ld_Tmp
string ls_value
curRow=1
//设置从EXCEL的第二行开始导入 
oBook=oXls.WorkBooks.Open(ls_excelpath)
oSheet=oXls.Sheets(1)
DO WHILE True
ls_value=http://www.mamicode.com/string(oSheet.Cells(curRow,1).Value)
//读取excel的内容放到变量中,cells(行,列)  
IF f_is_null(ls_value,"")="" THEN Exit
//如果遇到空,表示已经导入完成   
ll_Row=dw_1.InsertRow(0)
//给数据窗口增加行  
dw_1.setitem(curRow,"列名",string(ls_value))
curRow ++
LOOP
oBook.Close
DESTROY oSheet
DESTROY oBook
DESTROY oXls
return 0