我在網上找了段代碼,但總有一列導不進去,并且其他的匯入以后,原來的excel就無法打開,只能重新開機以后才能打開!請各位高手指教!代碼如下:
String ls_path,ls_name
ls_path = "C:\Documents and Settings\Administrator.FLYSTONE\桌面\新建檔案夾 (3)\test.xls"
dw_1.Reset() //clean DW
String a[1000,1000]
Integer i,j,li_ret
li_ret = GetFileopenName('選擇XLS',ls_path,ls_name,"XLS","EXCEL (*.XLS),*.XLS")
if li_ret <> 1 then return
OLEObject ExcelServer
Int li_ConnectErr
ExcelServer = Create OLEObject
ExcelServer.ConnectToNewObject( "excel.application" )
ExcelServer.Workbooks.Open(ls_path,0,False)
ExcelServer.Application.DisplayAlerts = False
ExcelServer.ActiveSheet.cells.Copy
dw_1.ImportClipboard(2) //匯入資料需要標題
ExcelServer.Application.activeworkbook.Close(False)
ExcelServer.Application.quit()
ExcelServer.DisconnectObject()
uj5u.com熱心網友回復:
你沒銷毀ExcelServer物件。這個代碼應該可以,我也是用這個。具體在除錯一哈。
uj5u.com熱心網友回復:
打開任務管理器,看看execl行程,你一直都沒關閉uj5u.com熱心網友回復:
樓主試試這個匯入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
uj5u.com熱心網友回復:
string str_savename,named,s_grxhint excelok,li_net
long li_count,i
oleobject excelserver
excelserver=create oleobject
excelok=excelserver.connecttonewobject("excel.application")
//查回傳值,以確保已成功地連接到ExcelExcel
if excelok <> 0 then
messagebox("資訊提示","連接EXCEL失敗,請確定是否裝有EXCEL!")
return -1
end if
li_net = GetFileOpenName("選擇檔案", str_savename,named,"xls","Excel檔案(*.xls),*.xls")
if li_net > 0 then
if str_savename = "" then return -1
dw_2.settransobject(sqlca)
dw_2.reset()
excelserver.workbooks.open(str_savename)
excelserver.activesheet.cells.copy
li_count = dw_2.importclipboard(2) //???擂
clipboard("")
excelserver.quit()
excelserver.disconnectobject()
destroy excelserver
return 1
else
messagebox('資訊提示','沒有指定檔案!')
return -1
end if
uj5u.com熱心網友回復:
真是奇怪,昨天不行的程式今天一試竟然可以了,還有一列就是導不進去,如果該列為空的話還不能保存,但資料庫中該列明明可以為空,這又是怎么回事???高手們指教一下!uj5u.com熱心網友回復:
//開始行,結束行Long ll_start_line
ll_start_line = 1
Long ll_end_line
//最後的行可以用下邊獲取,也可自己定義
ll_end_line = ExcelServer.ActiveSheet.UsedRange.Row - 1 + ExcelServer.ActiveSheet.UsedRange.Rows.Count
//開始列
Long ll_start_col
ll_start_col = 1
//結束列
Long ll_end_col
//最後的列可以用下邊獲取,也可自己定義
ll_end_col= ExcelServer.ActiveSheet.UsedRange.Column - 1 + ExcelServer.ActiveSheet.UsedRange.Columns.Count
dw_1.ImportClipboard(ll_start_line,ll_end_line,ll_start_col,ll_end_col
)
uj5u.com熱心網友回復:
mark...uj5u.com熱心網友回復:
<iframe title ="Preview" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" style="width:96px;height:96px;padding:0;background-color:#fcfcfc;" src="http://cid-5a271b0d5b2a3e58.photos.live.com/embedphoto.aspx/.res/5A271B0D5B2A3E58!137/5A271B0D5B2A3E58!134"></iframe>轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/86524.html
標籤:腳本語言
上一篇:系統不定時的提示:xxxx.exe非法操作,記憶體XXXXXXXX為只讀,是否向微軟報告錯誤
下一篇:pb如何呼叫dll指標引數
