我想实现把excel、word或text表格的数据导入powerbuild 9.0的数据窗口中,请哪位能给一个相应的代码??
我是新手,希望能把相关需要设置的控件以及内容给说明一下,先谢谢了……
------解决方案--------------------
一、对于excel与word的,先通过oleobject对象连接到对应的com再saveas成text格式;
二、text格式导入时调用importfile函数就好;
第一点可以到网上搜一下,有现成的代码;
------解决方案--------------------
Int i,k,result,result1,j
Long ll_row,ll_col,li_count,li_col_count
String ls_str,ls_tmp,ls_null,ls_mm,ls_sheet
IF IsNull(docname) Or sle_1.Text = '' THEN
MessageBox("注意","请先选择广告价格表excel文件")
RETURN
END IF
dw_yssj.Reset()
myoleobject1 = Create OLEObject
result = myoleobject1.ConnectToNewObject("excel.application")
re = result
String ls_exp
CHOOSE CASE result
CASE -1
ls_exp = '无效调用oleobject'
CASE -2
ls_exp = '未找到指定的oleobject类名'
CASE -3
ls_exp = '不能创建对象oleobject'
CASE -4
ls_exp = '不能连接到对象oleobject'
CASE -9
ls_exp = '其他错误'
CASE -15
ls_exp = '本计算机上未加载MTS'
CASE -16
ls_exp = '无效调用该函数不使用于OLETxnObject对象'
END CHOOSE
IF result <> 0 THEN
MessageBox('OLE错误','OLE无法连接,错误为:'+String(result)+':'+ls_exp)
RETURN
END IF
//IF Value <> 1 THEN RETURN
Open(w_ts)
SetNull(ls_mm)
SetNull(ls_null)
oldpointer = SetPointer(HourGlass!)
myoleobject1.Workbooks.Open(docname)
//ddlb_1.SelectItem( k)
ddlb_1.SelectedText()
ls_sheet = Trim(ddlb_1.Text)
IF ls_sheet = '' Or IsNull(ls_sheet) THEN
MessageBox("提示","请选择excel文件的sheet")
ddlb_1.SelectItem(1)
ddlb_1.Text = ddlb_1.Text(1)
RETURN
END IF
myoleobject1.ActiveWorkBook.Sheets(ls_sheet).SELECT
dw_xls.Reset ()
myoleobject1.activesheet.cells.Copy
il_col_count=myoleobject1.activesheet.usedRange.Columns.Count //列数
//ll_maxcol = myoleobject1.activesheet.usedRange.Columns.Count
li_count = dw_xls.ImportClipboard ( 1 ) //导入数据
Clipboard ( "" ) //清空剪贴板
//删除最后一行空行
IF dw_xls.GetItemString(dw_xls.RowCount(),"cs1") = '' Or IsNull(dw_xls.GetItemString(dw_xls.RowCount(),"cs1")) THEN
dw_xls.DeleteRow(dw_xls.RowCount())
END IF
dw_xls.AcceptText( )
cb_3.Enabled = True
Long i,j,k,m,n,p,ln_ggsx,ll_klj,q
Date ld_date,ld_date_tmp
String ls_ggdm,ls_dw,ls_bcsj,ls_ggsx,ls_ggsd,ls_jglx,ls_bcpd,ls_klj_qyrq,ls_col
String ls_qysj,ls_pddm,ls_bcsd,ls_kssj,ls_jssj,ls_tb,ls_kszt,ls_jszt,ls_jmlx,ls_zkl
Dec{2} ld_zkl
Open(w_ts)
//读取原始数据待处理,第19行为开始行
For i = 5 To dw_xls.RowCount()
ls_bcpd = dw_xls.GetItemString(i,"cs1") //播出频道
ls_klj_qyrq = dw_xls.GetItemString(i,"cs2") //启用时间
ls_pddm = dw_xls.GetItemString(i,"cs3") //频道代码
ls_bcpd = f_pddm_mczh(ls_pddm)
If ls_bcpd = '' Then
MessageBox("注意","频道名称为"+ls_bcpd+"代码为"+ls_pddm+"有误,请手工修改")
End If
ls_tb = dw_xls.GetItemString(i,"cs4") //套播
ls_bcsd = dw_xls.GetItemString(i,"cs5") //播出时段
ls_kssj = dw_xls.GetItemString(i,"cs6") //开始时间
ls_jssj = dw_xls.GetItemString(i,"cs7") //开始时间
ls_ggsd = dw_xls.GetItemString(i,"cs8") //广告时段
ls_jmlx = dw_xls.GetItemString(i,"cs9") //节目类型
ls_kszt = Trim(dw_xls.GetItemString(i,"cs10")) //开始周天
ls_jszt = Trim(dw_xls.GetItemString(i,"cs11")) //结束周天
If IsNull(ls_kszt) Then ls_kszt = Trim(dw_xls.GetItemString(i+1,"cs10")) //开始周天
If IsNull(ls_jszt) Then ls_jszt = Trim(dw_xls.GetItemString(i+1,"cs11")) //开始周天
For j = 12 To il_col_count-1