给个建议

lafite2003 2003-08-21 02:53:48
求用ole实现把数据窗口倒入excel 中的很具体的语法。因为Microsoft的帮助实在是太差了。
...全文
61 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
lafite2003 2003-08-31
  • 打赏
  • 举报
回复
谢谢各位.结帖
jackzhang168 2003-08-22
  • 打赏
  • 举报
回复
saveas
icedot 2003-08-22
  • 打赏
  • 举报
回复
haha ,我有一个很好的例子,可以在excel中生成表格。
给个邮箱,看看合不合适
hexubing 2003-08-22
  • 打赏
  • 举报
回复
帮顶
rogery 2003-08-22
  • 打赏
  • 举报
回复
要难度更大的??

楼主好水平%%

不过总得提一个需求分析吧^^????????
lafite2003 2003-08-21
  • 打赏
  • 举报
回复
谢谢几位大哥
上面这些基本的我都会。我求的是一些有些难度的。
上面这些只能完成一些规则报表。还有没有更好的。
txchen 2003-08-21
  • 打赏
  • 举报
回复
gz
runsoft 2003-08-21
  • 打赏
  • 举报
回复
saveas
derry_mr 2003-08-21
  • 打赏
  • 举报
回复
以下是大致的过程,已经过测试:

//ds_out为待输出的数据窗口
ls_file = "c:\test.excel"//输出EXCEL文件名

//输出
if this.ds_out.SaveAs(ls_file,"Excel5!",true) <> 1 then return false

oleobject ole_app,ole_excel
int li_rtn
ole_app = CREATE OLEObject
ole_excel = CREATE OLEObject
li_rtn = ole_app.ConnectToObject( "", "excel.application")
IF li_rtn <> 0 THEN
//如果excel还没有打开,则新建。
li_rtn = ole_app.ConnectToNewObject("excel.application")
if li_rtn <> 0 then
MessageBox('OLE错误','连接excel应用服务错误!~r~n错误代码:'+string(li_rtn))
return -1
end if
ole_app.Visible = false
end if

ole_excel = ole_app.Workbooks.Open(as_file)

if not ole_excel.Save() then
MessageBox('提示',"保存EXCEL文件错误!")
return -1
end if

ole_app.Visible = true
destroy ole_excel

Ole_app.DisConnectObject()
destroy ole_app

注意:原始的输出不尽人意,以下几点还需在输出前进行处理
1.DW中设为隐藏的列不显示
2.DW中列宽等于0的不显示
3.按照DW实际显示顺序输出
4.包含ChildDW的列要将数据内容转换成显示内容
eastpond 2003-08-21
  • 打赏
  • 举报
回复
/**********************************************
* 函数名称: f_dw_save_excel(datawindow,tile) *
* 函数用法:datawindow为要转化的数据窗口 dw_data; *
* tile为数据窗口的标题 tabname。 *
* 举例:changexecl(dw_1,"这是我们的世界") *

**********************************************/

long numcols , numrows , c, r
OLEObject xlapp , xlsub
int ret,coli
string colname,colname1

numcols = long(dw_data.Object.DataWindow.Column.Count)
numrows = dw_data.RowCount()

xlApp = Create OLEObject

ret = xlApp.ConnectToNewObject( "Excel.application" )
if ret < 0 then
MessageBox("Connect to Excel Failed !",string(ret))
return
end if

xlApp.Application.Workbooks.add()

xlApp.Application.Visible = true

xlsub = xlapp.Application.ActiveWorkbook.Worksheets[1]

string colnum //判断是A、B...或AA、AB...还是BA、BB、BC...
if integer(numcols) > 26 then
string colnumd,colnumd1
int numcols1,numcols2
numcols1 = mod(numcols,26)
numcols2 = numcols / 26
colnumd = char(numcols1 + 96)
colnumd1 = char(numcols2 + 96)
colnum ="'" + colnumd1 + colnumd + "'"
else
colnum = char(numcols + 96)
end if

xlsub.cells[1,1] = tabname //标题
xlsub.cells[1,1].HorizontalAlignment = 3
xlsub.cells[1,1].VerticalAlignment = 3
xlsub.cells[1,1].Font.Size = 20
xlsub.range("a1:" + colnum + "1").Merge()

string ls_colname
integer i
for i = 1 to numcols
//得到标题头的名字
ls_colname = dw_data.describe('#' + string(i) + ".name") + "_t"
xlsub.cells[2,i] = dw_data.describe(ls_colname + ".text")
next
//画表格线
string ls_range
ls_range = "A2:" + colnum + Trim(string(numrows+2))
xlsub.range(ls_range).borders(1).linestyle = 1
xlsub.range(ls_range).borders(2).linestyle = 1
xlsub.range(ls_range).borders(3).linestyle = 1
xlsub.range(ls_range).borders(4).linestyle = 1
//将数据写到EXECL
For c = 1 to numcols
For r = 1 to numrows
xlsub.cells[r + 2,c] = dw_data.object.data[r,c]
Next
Next

xlapp.Application.ActiveWorkbook.saved = false

xlApp.DisConnectObject()
Destroy xlapp
polugen 2003-08-21
  • 打赏
  • 举报
回复
The SaveAs PowerScript function, Syntax 1 for DataWindows and DataStores, has a new value for the saveastype argument: Excel5!
dingzhaofeng 2003-08-21
  • 打赏
  • 举报
回复
同上,使用数据窗口的saveas()来实现。
xingxing 2003-08-21
  • 打赏
  • 举报
回复
saveas

1,075

社区成员

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

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