求导入EXCEL到数据窗口的代码

cityscene2001 2007-06-21 04:20:31
求导入EXCEL到数据窗口的代码,最好是能够给出“读出EXCEL每一行和列的代码”,在转入到数据窗口前进行处理。
还有一个问题,在进行编译时,需要什么动态库,我在做导出的程序时,编译通不对,提示链接错误。
解决立即结贴。
...全文
797 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
tanjun132 2007-06-24
  • 打赏
  • 举报
回复
学习,好东西
yuanxiaolei 2007-06-22
  • 打赏
  • 举报
回复
http://www.zzcx.net.cn
jxl2910 2007-06-22
  • 打赏
  • 举报
回复
这个方法有些麻烦。可以在程序中先将excel另存为tab分割的txt文件,再dw_1.ImportFile()即可。代码如下:

SetPointer(HourGlass!)
//利用OLE对象,先将excel另存为tab分隔的文本文件,在导入这个文本文件到数据窗口
//最后删除这个文件
String ls_path,ls_filename,ls_saveasname
Long excelok
Integer li_gfo
li_gfo = GetFileOpenName("选择导出文件",ls_path,ls_filename,"DOC","Excel Files (*.xls),*.xls")
If li_gfo = 0 Then Return//取消操作
If li_gfo = -1 Then
gf_msg('载入失败!',2)
Return
End If

OLEObject ExcelServer
ExcelServer = Create OLEObject
excelok = ExcelServer.ConnectToNewObject( "excel.application" )
If excelok < 0 Then
MessageBox("连接excel失败,检查你的系统是否安装了office",String(excelok))
Return
Else
ExcelServer.Workbooks.OPEN(ls_path)
ls_saveasname = "c:\temp.txt"
ExcelServer.activeworkbook.SaveAs(ls_saveasname,3)
ExcelServer.displayalerts = False
ExcelServer.quit()
ExcelServer.DisconnectObject()
Destroy ExcelServer
dw_1.ImportFile(ls_saveasname)
FileDelete(ls_saveasname)
End If
dw_1.AcceptText()
starsong 2007-06-21
  • 打赏
  • 举报
回复
1.这个不需要特殊的动态库,不过要安装excel.
2.这个是我跟踪的时候用的,用于判断当前是否最后一行。
cityscene2001 2007-06-21
  • 打赏
  • 举报
回复
hi starsong


ll_test = len(string(xlsub.cells(i,1).value))
这一行什么意思,它返回什么

thank you
cityscene2001 2007-06-21
  • 打赏
  • 举报
回复
好的,谢谢,
还有,在编译成DLL文件时,我一用这个功能,它就提示编译不成功,用这个导出功能,需要特殊的动态库吗
starsong 2007-06-21
  • 打赏
  • 举报
回复
刚做过,看能不能用上
starsong 2007-06-21
  • 打赏
  • 举报
回复
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
messagebox("提示信息","文件不存在!请检查文件")
return
end if

long i,ll_row,i_return,ll_newrow
oleobject xlapp,xlsub //申明excel对象
xlapp = CREATE OLEObject //创建excel对象

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[1]
long ll_test
i = 1
ll_test = len(string(xlsub.cells(i,1).value))
do while len(string(xlsub.cells(i,1).value)) > 0
s_contractcode = trim(string(xlsub.cells(i,1).value))
ll_weight = dec(string(xlsub.cells(i,2).value))
s_steelcode = trim(string(xlsub.cells(i,3).value))
ls_remark = trim(string(xlsub.cells(i,4).value))
ll_newrow=dw_2.insertrow(0)
dw_2.object.b_zbszb_f_vc_htbh[ll_newrow] = s_contractcode
dw_2.object.b_zbszb_f_vc_zmsh[ll_newrow] = s_steelcode
dw_2.object.b_zbszb_f_nb_htsl[ll_newrow] = ll_weight
dw_2.object.b_zbszb_f_vc_bz[ll_newrow] = ls_remark
i = i+1
loop
xlapp.DisplayAlerts = False
xlapp.Workbooks.close
xlapp.DisplayAlerts = true
xlapp.DisconnectObject()
Destroy xlapp


cityscene2001 2007-06-21
  • 打赏
  • 举报
回复
自己顶一下,免得沉了

1,076

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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