假如安裝,請與程序供應商聯系 !",QuesTion!) RETURN -1 END IF //增加空文檔 (EXCEL table) xlApp.Workbooks.Open(as_excelfile) //xlApp.Application.Visible = FALSE xlApp.DisplayAlerts = false //定位到第壹格 Long l_cnt,l_rows,l_cols Long l_row,l_i Int i_cnt l_rows = 30 l_cols = 23 Long l_cno String s_cno,s_temp Long l_newrow //壹次處理兩行 DataStore ds_todb IF NOT IsValid(ds_todb) THEN ds_todb = CREATE DataStore END IF ds_todb.DataObject = "dw_getdatafromexcel" ds_todb.SetTransObject(at_sqlca) FOR l_cnt = 2 TO l_rows STEP 2 Yield() l_row = l_cnt s_cno = String(xlapp.activeworkbook.activesheet.cells[l_row - 1,1].value) IF NOT IsNumber(s_cno) THEN CONTINUE FOR l_row = l_cnt - 1 TO l_cnt s_cno = xlapp.activeworkbook.activesheet.cells[l_row,1].FormulaR1C1 IF IsNull(s_cno) OR s_cno = "" THEN //非新行 FOR l_i = 4 TO l_cols STEP 2 s_temp = String(Trim(xlapp.activeworkbook.activesheet.cells[l_row,l_i].FormulaR1C1)) IF IsNull(s_temp) OR s_temp = "" THEN CONTINUE i_cnt++ ds_todb.SetItem(l_newrow,i_cnt,s_temp) NEXT ELSE //新行開始,清空數組 IF NOT IsNumber(s_cno) THEN CONTINUE l_newrow = ds_todb.InsertRow(0) ds_todb.SetItem(l_newrow,1,s_cno) //ds_todb.SetItem(l_newrow,2,gnvo_db.uf_todate(Long(xlapp.activeworkbook.activesheet.cells[l_ row,2].FormulaR1C1))) ds_todb.SetItem(l_newrow,3, Dec(xlapp.activeworkbook.activesheet.cells[l_row,3].FormulaR1C1)) i_cnt = 3 FOR l_i = 4 TO l_cols STEP 2 s_temp = String(Trim(xlapp.activeworkbook.activesheet.cells[l_row,l_i].FormulaR1C1)) IF IsNull(s_temp) OR s_temp = "" THEN CONTINUE i_cnt++ ds_todb.SetItem(l_newrow,i_cnt,s_temp) NEXT END IF NEXT NEXT xlApp.activeworkbook.close(false) xlapp.Application.quit() xlApp.DisConnectObject() //xlApp.Application.Workbooks.quit() IF IsValid(xlApp) THEN DESTROY xlapp END IF //gnvo_db.uf_closewin("Microsoft excel") IF ds_todb.Update() = 1 THEN COMMIT USING at_sqlca; MessageBox("導入數據","保存成功") ELSE ROLLBACK USING at_sqlca; MessageBox("導入數據","保存失敗") END IF IF IsValid(ds_todb) THEN DESTROY ds_todb END IF //FileDelete(as_excelfile) RETURN 1 Is_syspath=space(255) GetCurrentDirectoryA(255,Is_syspath) value=GetFileopenname(" 請選擇要導入 BOM 的 EXECL 類型文件!",ls_path,ls_filename,'xls','EXECL 文件(*.xls),*.xls') is_filename = mid(ls_filename,1,len(ls_filename) - 4) if value <> 1 then ////沒取到、或者取消返回 Return false end if Top 7 樓workhand(我可憨了...)回復於 2004-04-16 08:21:24 得分 0 Is_syspath=space(255) GetCurrentDirectoryA(255,Is_syspath) value=GetFileopenname(" 請選擇要導入 BOM 的 EXECL 類型文件!",ls_path,ls_filename,'xls','EXECL 文件(*.xls),*.xls') is_filename = mid(ls_filename,1,len(ls_filename) - 4) if value <> 1 then ////沒取到、或者取消返回 Return false end if 第壹種方法 OLEObject ExcelServer long excelok string str_savename ExcelServer = CREATE OLEObject ExcelOK = ExcelServer.ConnectToNewObject( "excel.application" ) if excelok < 0 then messagebox("連接excel 失敗,檢查妳的系統是否安裝了office",string(excelok)) return false else ExcelServer.Workbooks.Open(str_filename) str_savename="c:\temp.txt" excelserver.activeworkbook.saveas(str_savename,3) excelserver.displayalerts=false ExcelServer.quit() ExcelServer.DisconnectObject() DESTROY ExcelServer dw_acton.ImportFile(str_savename) filedelete(str_savename) return true end if 第二種方法 string ls_title, ls_str OLEObject xl, xlApp, xlbook, xlsheet xl = Create OLEObject st_stat.text = '正在連接...' int ret = 0 ret = xl.ConnectToObject(is_path, "Excel.Sheet" ) //打開壹個已存在的工作表 if ret < 0 then messagebox("提示","不能打開所選的文件,可能是已被別人打開!") destroy xl return end if xlApp = xl.Application xlbook = xlapp.Workbooks[1] xlsheet = xlbook.Worksheets[1] //////// ////// ////// ////////以下是讀數據部分, 首先判斷有幾行數據,前面幾個都為空時則數據結束 long ll_i,ll_row,ll_ll int li_start //從第幾行開始是真正的數據 li_start = 4 //從第n 行開始是真正的數據 // do while ((ll_ll < 5) and (ll_i < 3000)) ll_i += 1 ls_str = xlsheet.cells[ ll_i,4 ].text //貨物名稱 ll_row = ll_i if ls_str = "" then ll_ll = 1 ls_str = xlsheet.cells[ ll_i,5 ].text if ls_str = "" then ll_ll += 1 ls_str = xlsheet.cells[ ll_i,6 ].text if ls_str = "" then ll_ll += 1 ls_str = xlsheet.cells[ ll_i+1,4 ].text if ls_str = "" then ll_ll += 1 ls_str = xlsheet.cells[ ll_i+2, 4 ].text if ls_str = "" then ll_ll += 1 end if end if end if end if end if loop // if ll_row > 2800 then messagebox("錯誤","行數太多, 不能導入!") goto l_exit end if //壹***有ll_row - start 行 //// //ls_title = xlsheet.cells[1,1].text //標題, 這裏可能有比較 //// ls_str = xlsheet.cells[1,2].text //合同號 if ls_str <> is_contractcode then messagebox( "導入出錯","合同號不符,請檢查[1,2]單元格" ) st_stat.text = "導入失敗, 請退出重來!" goto l_exit end if //// //ls_str = xlsheet.cells[2,2].text //合同名 //if ls_str <> is_contractname then // messagebox( "導入出錯","合同名不符,請檢查[2,2]單元格" ) // st_stat.text = "導入失敗, 請退出重來!" // goto l_exit //end if //// ////開始導入真正的數據 string ls_temp,ls_find long l_count,l_temp if (ll_row - 1) = li_start then messagebox( "提示","沒有數據可導!請檢查EXCEL 表格後,重來!" ) return end if for ll_i = li_start to ll_row - 1 st_stat.text = "正在導入第 " + string( ll_i - li_start + 1 ) + " 行," + '***有'+ string( ll_row - li_start) + '行' hpb_1.position = (( ll_i - li_start + 1 ) * 100/(ll_row - li_start)) l_count = dw_2.insertrow( 0 ) dw_2.setrow( l_count ) dw_2.object.f_id[ l_count ] = gf_get_max( 't_goodslist' ) //ID dw_2.object.f_contractid[ l_count ] = il_contractid //合同ID //從文件導入部分 dw_2.object.f_period[ l_count ] = xlsheet.cells[ ll_i, 1].text //期別 dw_2.object.f_mysys[ l_count ] = xlsheet.cells[ ll_i, 2].text //系統碼 dw_2.object.f_goodscode[ l_count ] = xlsheet.cells[ ll_i, 3].text //貨物編碼 dw_2.object.f_goodsname[ l_count ] = xlsheet.cells[ ll_i, 4].text //貨物名稱 dw_2.object.f_specif[ l_count ] = xlsheet.cells[ ll_i, 5].text //貨物規格 dw_2.object.f_parameter[ l_count] = xlsheet.cells[ ll_i, 6].text //主要技術參數 dw_2.object.f_factory[ l_count ] = xlsheet.cells[ ll_i, 7].text //制造廠 dw_2.object.f_goodstype[ l_count ] = xlsheet.cells[ ll_i, 8].text //貨物類別 dw_2.object.f_unit[ l_count ] = xlsheet.cells[ ll_i, 9].text //單位 //數量 ls_str = xlsheet.cells[ ll_i, 10].text if not isnumber( ls_str ) and ls_str <> '' then messagebox("錯誤","第["+ string( ll_i) + ',10]單元格必須是數字!') goto l_exit end if dw_2.object.f_quant[ l_count ] = dec(ls_str ) //數量 //出廠價 ls_str = xlsheet.cells[ ll_i, 11].text if not isnumber( ls_str ) and ls_str<>'' then messagebox("錯誤","第["+ string( ll_i) + ',11]單元格必須是數字!') goto l_exit end if dw_2.object.f_outprice[ l_count ] = dec(ls_str ) //出廠價 //運輸價 ls_str = xlsheet.cells[ ll_i, 12].text if not isnumber( ls_str ) and ls_str<>'' then messagebox("錯誤","第["+ string( ll_i) + ',12]單元格必須是數字!') goto l_exit end if dw_2.object.f_transprice[ l_count ] = dec(ls_str ) //運輸價 //保險價 ls_str = xlsheet.cells[ ll_i, 13].text if not isnumber( ls_str ) and ls_str<>'' then messagebox("錯誤","第["+ string( ll_i) + ',13]單元格必須是數字!') goto l_exit end if dw_2.object.f_guaranteep[ l_count ] = dec(ls_str ) //保險價 //其它價 ls_str = xlsheet.cells[ ll_i, 14].text if not isnumber( ls_str ) and ls_str<>'' then messagebox("錯誤","第["+ string( ll_i) + ',14]單元格必須是數字!') goto l_exit end if dw_2.object.f_otherprice[ l_count ] = dec(ls_str ) //其它價 //綜合單價 ls_str = xlsheet.cells[ ll_i, 15].text if not isnumber( ls_str ) and ls_str <> '' then messagebox("錯誤","第["+ string( ll_i) + ',15]單元格必須是數字!') goto l_exit end if dw_2.object.f_unitprice[ l_count ] = dec(ls_str ) //綜合單價 //外幣總價 ls_str = xlsheet.cells[ ll_i, 16].text if not isnumber( ls_str ) and ls_str <> '' then messagebox("錯誤","第["+ string( ll_i) + ',16]單元格必須是數字!') goto l_exit end if dw_2.object.f_totalprice[ l_count ] = dec(ls_str ) //外幣總價 dw_2.object.f_currency[ l_count ] = xlsheet.cells[ ll_i, 17].text //幣種 //匯率 ls_str = xlsheet.cells[ ll_i, 18].text if not isnumber( ls_str ) and ls_str <> '' then messagebox("錯誤","第["+ string( ll_i) + ',18]單元格必須是數字!') goto l_exit end if dw_2.object.f_exchange[ l_count ] = dec(ls_str ) //匯率 //匯率日期 ls_str = xlsheet.cells[ ll_i, 19].text if not isdate( ls_str ) and ls_str <> '' then messagebox("錯誤","第["+ string( ll_i) + ',19]單元格必須是日期!') goto l_exit end if dw_2.object.f_exchangedate[ l_count ] = datetime(date(ls_str )) //匯率日期 //人民幣單價 ls_str = xlsheet.cells[ ll_i, 20].text if not isnumber( ls_str ) and ls_str <> '' then messagebox("錯誤","第["+ string( ll_i) + ',20]單元格必須是數字!') goto l_exit end if dw_2.object.f_rmbunitprice[ l_count ] = dec(ls_str ) //人民幣單價 //人民幣總價 ls_str = xlsheet.cells[ ll_i, 21].text if not isnumber( ls_str ) and ls_str <> '' then messagebox("錯誤","第["+ string( ll_i) + ',21]單元格必須是數字!') goto l_exit end if dw_2.object.f_rmbtotalprice[ l_count ] = dec(ls_str ) //人民幣總價 //開始日期 ls_str = xlsheet.cells[ ll_i, 22].text if not isdate( ls_str ) and ls_str <> '' then messagebox("錯誤","第["+ string( ll_i) + ',22]單元格必須是日期!') goto l_exit end if dw_2.object.f_startdate[ l_count ] = datetime(date(ls_str )) //開始日期 //結束日期 ls_str = xlsheet.cells[ ll_i, 23].text if not isdate( ls_str ) and ls_str <> ''then messagebox("錯誤","第["+ string( ll_i) + ',23]單元格必須是日期!') goto l_exit end if dw_2.object.f_enddate[ l_count ] = datetime(date(ls_str )) //結束日期 dw_2.object.f_station[l_count] = xlsheet.cells[ ll_i,24].text //站點 dw_2.object.f_place[l_count] = xlsheet.cells[ ll_i,25].text //安裝位置 dw_2.object.f_gaisuan[l_count]= xlsheet.cells[ ll_i,26].text //概算碼 dw_2.object.f_memo[l_count]= xlsheet.cells[ ll_i,27].text //備註 //其它信息 dw_2.object.f_stat[l_count] = 0 dw_2.object.f_compquant1[l_count] = 0 dw_2.object.f_compquant2[l_count] = 0 dw_2.object.f_inquant1[l_count] = 0 dw_2.object.f_inquant2[l_count] = 0 dw_2.object.f_payquant[ l_count ] = 0 dw_2.object.f_changestat[ l_count ] = 0 dw_2.object.f_changecount[ l_count ] = 0 next st_stat.text = '導入成功!請選擇[保存]或[取消]。 保存--此次導入數據將提交到數據庫中,取消--則不提交!
上一篇:保留什麽樣的產品?下一篇:弟子規全文翻譯