PB讀取Excel檔案內容的方法(轉帖)

hljhrbsjf發表於2011-04-15

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部落格 ” ,連結:http://blog.itpub.net/631872/viewspace-1048718/,如需轉載,請註明出處,否則將追究法律責任。

相關文章