分享
 
 
 

PowerBulider数据窗口转MicroSoft Execl、Word程序源代码

王朝other·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

PowerBulider数据窗口转MicroSoft Execl、Word程序源代码

一、f_cncharnum函数 f_cncharnum.srf

$PBExportHeader$f_cncharnum.srf

$PBExportComments$得到字符串中汉字或者双字节的个数

global type f_cncharnum from function_object

end type

forward prototypes

global function integer f_cncharnum (string aString)

end prototypes

global function integer f_cncharnum (string aString);

//函数名: f_cncharnum

//用途: 返回一个字符串中汉字的个数

//输入: aString - string, 给定的字符串

//返回值: li_num - Integer, 给定的字符串中汉字的个数

//注意: 1. 此方法基于汉字的国标汉字库区位编码的有效性,不符合此编码的系统此函数无效!

// 2. 若汉字串含有非汉字字符,如图形符号或ASCII码,则这些非汉字字符将保持不变.

//例如: li_ret = f_cncharnum("摆渡人ferryman") li_ret = 3

string ls_ch //临时单元

string ls_SecondSecTable //存放所有国标二级汉字读音

integer li_num = 0 //返回值

integer i,j

For i = 1 to Len(aString)

ls_ch = Mid(aString,i,1)

If Asc(ls_ch) >= 128 then //是汉字

li_num++

i = i+1

End if

Next

Return li_num

end function

二、PBToExcel函数f_outputtoexcel_new.srf

$PBExportHeader$f_outputtoexcel_new.srf

global type f_outputtoexcel_new from function_object

end type

forward prototypes

global function integer f_outputtoexcel_new (datawindow adw)

end prototypes

global function integer f_outputtoexcel_new (datawindow adw);

//函数名:f_outputtoexcel_new

//输入: adw - datawindow,指定的数据窗口

//返回值: Integer

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 = True

END IF

pointer oldpointer

oldpointer = SetPointer(HourGlass!)

ole_object.Workbooks.Add

long ll_colnum,ll_rownum

string ls_value

string ls_objects,ls_obj,ls_objs[],ls_objtag[]

long ll_pos,ll_len,ll_num = 0

ls_objects = trim(adw.Describe('datawindow.Objects'))

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 + '.tag')

end if

ls_objects = right(ls_objects,len(ls_objects) - ll_pos)

loop

//得到数据窗口数据的列数与行数(行数应该是数据行数 + 1)

ll_colnum = ll_num

ll_rownum = adw.rowcount() + 1

string ls_colname

integer i,j,k

for i = 1 to ll_colnum

//得到标题头的名字

ls_value = ls_objtag[i]

ole_object.cells(1,i).value = ls_value

next

string column_name

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

ole_object.cells(i,j).value = ls_value

next

next

SetPointer(oldpointer)

ole_object.disconnectobject()

DESTROY ole_object

return 1

end function

三、PBToWord函数f_outputtoword_new.srf

$PBExportHeader$f_outputtoword_new.srf

global type f_outputtoword_new from function_object

end type

forward prototypes

global function integer f_outputtoword_new (datawindow adw)

end prototypes

global function integer f_outputtoword_new (datawindow adw);

//函数名:f_outputtoword_new

//输入: adw - datawindow,指定的数据窗口

//返回值: Integer

constant integer ppLayoutBlank = 12

OLEObject ole_object

ole_object = CREATE OLEObject

integer li_ret

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

ls_objects = trim(adw.Describe('datawindow.Objects'))

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 + '.tag')

end if

ls_objects = right(ls_objects,len(ls_objects) - ll_pos)

loop

//得到数据窗口数据的列数与行数(行数应该是数据行数 + 1)

ll_colnum = ll_num

ll_rownum = adw.rowcount() + 1

ole_object.Documents.Add()

ole_object.ActiveDocument.Tables.Add(ole_object.Selection.Range, ll_rownum, ll_colnum)

string ls_colname

integer i,j,k

for i = 1 to ll_colnum

//得到标题头的名字

ls_value = ls_objtag[i]

ole_object.Selection.TypeText(ls_value)

for k = 1 to f_cncharnum(ls_value)

ole_object.Selection.TypeBackspace()

next

ole_object.Selection.MoveRight(wdCell)

next

adw.setredraw(false)

ole_object.Selection.MoveLeft(wdCell)

string column_name

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

ole_object.Selection.MoveRight(wdCell)

ole_object.Selection.TypeText(ls_value)

for k = 1 to f_cncharnum(ls_value)

ole_object.Selection.TypeBackspace()

next

next

next

adw.setredraw(true)

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

return 1

end function

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有