在窗口中打开并显示EXCEL文件

smxwyh 2003-10-20 11:10:59
请问:
在PB的窗口中用getfileopenname()取得一个excel路径文件名,然后通过窗口中的ole控件显示出来。请问如何实现?多谢!
...全文
96 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
qqjj7758 2003-10-20
  • 打赏
  • 举报
回复
忘记说了 上面是从数据窗口取数 放入EXCEL再打开的过程
希望对你有帮助
qqjj7758 2003-10-20
  • 打赏
  • 举报
回复
//adw datawindow
//reptitle string

constant integer ppLayoutBlank = 12
OLEObject ole_object
ole_object = CREATE OLEObject

integer li_ret

li_ret = ole_object.ConnectToObject("","Excel.Application")
IF li_ret <> 0 THEN
//如果Excel还没有打开,则新建。
li_ret = ole_object.ConnectToNewObject("Excel.Application")
if li_ret <> 0 then
MessageBox('OLE错误','OLE无法连接!错误号:' + string(li_ret))
return 0
end if
ole_object.Visible = False//True 输数据时EXCEL是否可见
END IF

pointer oldpointer

oldpointer = SetPointer(HourGlass!)
open(w_wait_excel)
ole_object.Workbooks.Add()

long ll_colnum,ll_rownum
string ls_value

string ls_objects,ls_obj,ls_objs[],ls_objtag[],ls_width[]
long ll_pos,ll_len,ll_num = 0

ls_objects = trim(adw.Describe('datawindow.Objects'))
//hj
do while (pos(ls_objects,"~t") >0)
ll_pos = pos(ls_objects,"~t")
ll_len = ll_pos - 1
ls_obj = left(ls_objects,ll_len)
if (adw.Describe(ls_obj + '.type') = 'column' or &
adw.Describe(ls_obj + '.type') = 'compute') and &
(adw.Describe(ls_obj + '.band') = 'detail') and (ls_obj <> "asd") then
ll_num += 1
ls_objs[ll_num] = ls_obj //数据窗口中有的列

ls_objtag[ll_num] = adw.Describe(ls_obj +'_t' + '.text') //列汉字名字
ls_width[ll_num]= adw.Describe(ls_obj +'_t' + '.width') //每列的宽度

end if
ls_objects = right(ls_objects,len(ls_objects) - ll_pos)
loop
/////////hj add
if (adw.Describe(ls_obj + '.type') = 'column' or &
adw.Describe(ls_obj + '.type') = 'compute') and &
(adw.Describe(ls_obj + '.band') = 'detail') and (ls_obj <> "asd") then
ll_num += 1
ls_objs[ll_num] = ls_objects //数据窗口中有的列

ls_objtag[ll_num] = adw.Describe(ls_objects +'_t' + '.text') //列汉字名字
ls_width[ll_num]= adw.Describe(ls_objects +'_t' + '.width') //每列的宽度

end if

/////////

//得到数据窗口数据的列数与行数(行数应该是数据行数 + 2)
ll_colnum = ll_num
ll_rownum = adw.rowcount() +1// 2

/*//生成标题
ole_object.Cells(1,1).Value =reptitle
ole_object.Range('A1').Select
ole_object.Selection.Font.Size =24
//hj
ole_object.selection.HorizontalAlignment =3
//hj
ole_object.Range('A1:'+f_columname(ll_colnum)+'1').Select
ole_object.Range('A1:'+f_columname(ll_colnum)+'1').Merge */


string ls_colname
integer k,i,j
dec ld_width


for i = 1 to ll_colnum
//得到标题头的名字
ls_value = ls_objtag[i]
ole_object.cells(1,i).value = ls_value //1
if isnull(ls_width[i]) then
ld_width=12
else
ld_width=dec(ls_width[i])/35
end if
ole_object.Columns(i).ColumnWidth=ld_width
//hj
ole_object.Columns(i).HorizontalAlignment =3

ole_object.Columns(i).Borders.LineStyle= 1
ole_object.Columns(i).Font.Bold =True
////hjadd
ole_object.Columns(i).Font.Size =10
next

string column_name,ls_coltype
for i = 2 to ll_rownum
for j = 1 to ll_colnum
column_name = ls_objs[j]
if adw.Describe(column_name + '.type') = 'column' then
ls_value = adw.Describe("Evaluate('LookupDisplay("+column_name+")',"+string(i - 1)+")")
end if
if adw.Describe(column_name + '.type') = 'compute' then
ls_value = adw.Describe("Evaluate('" + adw.Describe(column_name + '.expression') + "',"+string(i - 1)+")")
end if

ls_coltype=adw.Describe(column_name+'.coltype')
if pos(upper(ls_coltype),"CHAR")>0 then //对字符型数据处理
ole_object.cells(i,j).NumberFormat ="@"
end if
//hjadd
ole_object.cells(i,j).HorizontalAlignment =1
ole_object.cells(i,j).Font.Bold =false
//hjadd
ole_object.Columns(i).Font.Size =10
ole_object.cells(i,j).value = ls_value
next
next
close(w_wait_excel)
ole_object.Visible = True
SetPointer(oldpointer)


ole_object.disconnectobject()
DESTROY ole_object
0清风0 2003-10-20
  • 打赏
  • 举报
回复
我一开始在硬盘上创建了一个doc文件,因为我的文件是在数据库里得。
D:\szw1.doc
0清风0 2003-10-20
  • 打赏
  • 举报
回复
这个是用来打开 word得,没直接用 ole,不过是动态得,你可以改改。Word 和 Excel差不多。
constant integer ppLayoutBlank = 12
OLEObject ole_object
ole_object = CREATE OLEObject
integer li_ret
string ls_colname
integer i,j,k
li_ret = ole_object.ConnectToObject("","word.application")
IF li_ret <> 0 THEN
//如果Word还没有打开,则新建。
li_ret = ole_object.ConnectToNewObject("word.application")
if li_ret <> 0 then
MessageBox('OLE错误','OLE无法连接!错误号:' + string(li_ret))
return 0
end if
ole_object.Visible = True
END IF

long ll_colnum,ll_rownum
constant long wdWord9TableBehavior = 1
constant long wdAutoFitFixed = 0
constant long wdCell = 12
string ls_value
pointer oldpointer

oldpointer = SetPointer(HourGlass!)

string ls_objects,ls_obj,ls_objs[],ls_objtag[]
long ll_pos,ll_len,ll_num = 0



ole_object.Documents.Add("D:\szw1.doc")


constant long wdFormatDocument = 0

SetPointer(oldpointer)
//保存新建的文档
if messagebox("保存","文档已经成功完成,是否保存?",Question!,YesNo!) = 1 then
string docname, named
integer value

value = GetFileSaveName("选择文件",docname, named, "DOC","Doc Files (*.DOC), *.DOC")

IF value = 1 THEN
ole_object.ActiveDocument.SaveAs(docname, 0,False,"",True,"",False,False,False, False,False)
end if

end if
//断开OLE连接
Ole_Object.DisConnectObject()
Destroy Ole_Object

740

社区成员

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

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