ITPub博客

首页 > 应用开发 > IT综合 > PB读取Excel文件内容的方法(转帖)

PB读取Excel文件内容的方法(转帖)

原创 IT综合 作者:hljhrbsjf 时间:2011-04-15 15:07:49 0 删除 编辑

string path_name,file_name

if GetFileOpenName( "选择导入的文件... ", path_name, file_name, "XLS ", "Excel Files (*.XLS),*.XLS ") = 1 then
else
return
end if

if fileexists(path_name) then
else
return
end if

long i,ll_row,i_return
oleobject xlapp,xlsub
xlapp = CREATE OLEObject

i_return = xlapp.ConnectToNewObject( "Excel.Application ")
if i_return <> 0 then
MessageBox( "错误! ", "无法启动excel程序! ")
return
end if

xlapp.application.workbooks.open(path_name)
xlsub = xlapp.application.activeworkbook.worksheets[2]
do while len(string(xlsub.cells(i,9).value)) > 0
goods_code = trim(string(xlsub.cells(i,9).value))
goods_num = double(xlsub.cells(i,5).value)
goods_price = double(xlsub.cells(i,6).value)
goods_sum_value = round(double(xlsub.cells(i,7).value),2)
goods_name = trim(string(xlsub.cells(i,1).value))
i = i + 1
loop
xlapp.DisplayAlerts = False
xlapp.Workbooks.close
xlapp.DisplayAlerts = true
xlapp.DisconnectObject()
Destroy xlapp

[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/631872/viewspace-1048718/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    114
  • 访问量
    544669