在数据窗口里,怎样导入excel表中的数据?

yannywang 2003-05-18 03:38:56
我想将excel表中的数据导入dw中,在pb中能做吗?具体怎样做?在线等侍,急!!!
...全文
52 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
dengxun78 2003-05-19
  • 打赏
  • 举报
回复
同意sunsg()的观点。。。
morningdew 2003-05-19
  • 打赏
  • 举报
回复
同意sunsg()的观点。。。存成TXT比较好一些。。注意用TAB分隔。
taobujue 2003-05-19
  • 打赏
  • 举报
回复
up
yannywang 2003-05-19
  • 打赏
  • 举报
回复
那么怎样存成 txt的格式,又怎样打开?
sunsg 2003-05-18
  • 打赏
  • 举报
回复
pb导入dw数据提供的函数只支持txt和dbf格式,excel格式可能不行,如果用程序控制,特别麻烦,还是将excel格式另存为txt
xirumin 2003-05-18
  • 打赏
  • 举报
回复
string ls_title, ls_str

OLEObject xl, xlApp, xlbook, xlsheet
xl = Create OLEObject
st_stat.text = '正在连接...'
int ret = 0
ret = xl.ConnectToNewObject("Excel.Application" ) //打开一个已存在的工作表
if ret < 0 then
messagebox("提示","不能打开所选的文件,可能是已被别人打开!")
destroy xl
return
end if

xlApp = xl.Application
xlApp.workbooks.open( is_path )
xlbook = xlapp.activeWorkbook
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 = trim(xlsheet.cells[ ll_i,1 ].text) //货物名称
ll_row = ll_i
if ls_str = "" then
ll_ll = 1
ls_str = trim(xlsheet.cells[ ll_i,1 ].text)
if ls_str = "" then
ll_ll += 1
ls_str = trim(xlsheet.cells[ ll_i,1 ].text)
if ls_str = "" then
ll_ll += 1
ls_str = trim(xlsheet.cells[ ll_i+1,1 ].text)
if ls_str = "" then
ll_ll += 1
ls_str = trim(xlsheet.cells[ ll_i+2, 1 ].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 = trim(xlsheet.cells[1,2].text) //合同号
if ls_str <> is_contractcode then
messagebox( "导入出错","合同号不符,请检查[1,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 -1 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_guarantee' ) //ID
dw_2.object.f_contractid[ l_count ] = il_contractid //合同ID
//从文件导入部分
dw_2.object.f_code[ l_count ] = trim(xlsheet.cells[ ll_i, 1].text) //期别
dw_2.object.f_guaranteetype [l_count ] = trim(xlsheet.cells[ ll_i, 2].text) //系统码
dw_2.object.f_name[ l_count ] = trim(xlsheet.cells[ ll_i, 3].text) //货物编码
//保证金额
ls_str = trim(xlsheet.cells[ ll_i, 4].text)
if not isnumber( ls_str ) and ls_str <> '' then
messagebox("错误","第["+ string( ll_i) + ',D]单元格必须是数字!')
goto l_exit
end if
dw_2.object.f_amount[ l_count ] = dec( ls_str ) //保证金额

dw_2.object.f_currency[ l_count ] = trim(xlsheet.cells[ ll_i, 5].text) //币种

//汇率
ls_str = trim(xlsheet.cells[ ll_i, 6].text)
if not isnumber( ls_str ) and ls_str <> '' then
messagebox("错误","第["+ string( ll_i) + ',F]单元格必须是数字!')
goto l_exit
end if
dw_2.object.f_exchange[ l_count ] = dec(ls_str ) //汇率

//汇率日期
ls_str = trim(xlsheet.cells[ ll_i, 7].text)
if not isdate( ls_str ) and ls_str <> '' then
messagebox("错误","第["+ string( ll_i) + ',G]单元格必须是日期!')
goto l_exit
end if
dw_2.object.f_exchangedate[ l_count ] = datetime(date(ls_str )) //汇率日期

//人民币金额
ls_str = trim(xlsheet.cells[ ll_i, 8].text)
if not isnumber( ls_str ) and ls_str <> '' then
messagebox("错误","第["+ string( ll_i) + ',H]单元格必须是数字!')
goto l_exit
end if
dw_2.object.f_rmbamount[ l_count ] = dec(ls_str ) //汇率

//开证日期
ls_str = trim(xlsheet.cells[ ll_i, 9].text)
if not isdate( ls_str ) and ls_str <> '' then
messagebox("错误","第["+ string( ll_i) + ',I]单元格必须是日期!')
goto l_exit
end if
dw_2.object.f_opendate[ l_count ] = datetime(date(ls_str )) //汇率日期
//有效其
dw_2.object.f_validlimit[ l_count ] = trim(xlsheet.cells[ ll_i, 10].text)
dw_2.object.f_openbank[ l_count ] = trim(xlsheet.cells[ ll_i, 11].text)
dw_2.object.f_passbank[ l_count ] = trim(xlsheet.cells[ ll_i, 12].text)
dw_2.object.f_transtype[ l_count ] = trim(xlsheet.cells[ ll_i, 13].text)

//收到日期
ls_str = trim(xlsheet.cells[ ll_i, 14].text)
if not isdate( ls_str ) and ls_str <> '' then
messagebox("错误","第["+ string( ll_i) + ',N]单元格必须是日期!')
goto l_exit
end if
dw_2.object.f_arrivedate[ l_count ] = datetime(date(ls_str )) //汇率日期

//审核日期
ls_str = trim(xlsheet.cells[ ll_i, 15].text)
if not isdate( ls_str ) and ls_str <> '' then
messagebox("错误","第["+ string( ll_i) + ',O]单元格必须是日期!')
goto l_exit
end if
dw_2.object.f_opendate[ l_count ] = datetime(date(ls_str) ) //汇率日期

dw_2.object.f_bankidea[ l_count ] = trim(xlsheet.cells[ ll_i, 16 ].text)
dw_2.object.f_myidea[ l_count ] = trim(xlsheet.cells[ ll_i, 17 ].text)

//上传日期
ls_str = trim(xlsheet.cells[ ll_i, 18].text)
if not isdate( ls_str ) and ls_str <> '' then
messagebox("错误","第["+ string( ll_i) + ',R]单元格必须是日期!')
goto l_exit
end if
dw_2.object.f_arrivedate[ l_count ] = datetime(date(ls_str) ) //汇率日期
//经手人
dw_2.object.f_pass[ l_count ] = trim(xlsheet.cells[ ll_i,19 ].text)



next
st_stat.text = '导入成功!请选择[保存]或[取消]。 保存--此次导入数据将提交到数据库中,取消--则不提交!'
cb_ok.of_setenabled( true )
cb_start.of_setenabled( false )

////
//////有错退出, 主要是要释放内存
l_exit:
xlapp.quit//xl.close()
xl.DisConnectObject()
Destroy xl
//
//return true

611

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder DataWindow
社区管理员
  • DataWindow社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧