200分在线求助一个问题,大家请进!!!!

hzslx 2003-02-19 06:05:17
问题就是如何在PB中带参数打开word,excel,望不吝指教!!谢谢!!
...全文
48 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
dotnba 2003-02-20
  • 打赏
  • 举报
回复
收藏
pearl2002 2003-02-20
  • 打赏
  • 举报
回复

最新的PBToExcel和PBToWord函数源代码 (文/张 涛)

1、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);//作者: 张涛
//邮件: ztao@engineer.com
//主页: 摆渡人工作室(http://pbsite.yeah.net/)
//函数名: 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

2、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);/作者: 张涛
//邮件: ztao@engineer.com
//主页: 摆渡人工作室(http://pbsite.yeah.net/)
//函数名: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

3、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);/作者: 张涛
//邮件: ztao@engineer.com
//主页: 摆渡人工作室(http://pbsite.yeah.net/)
//函数名: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
hzslx 2003-02-20
  • 打赏
  • 举报
回复
呵呵
谢谢大家
结帐了
liaolwj 2003-02-20
  • 打赏
  • 举报
回复
收藏!
xlhl 2003-02-19
  • 打赏
  • 举报
回复
收藏!
fengzeng 2003-02-19
  • 打赏
  • 举报
回复
收藏!
ice2water 2003-02-19
  • 打赏
  • 举报
回复
收藏
zqbchina 2003-02-19
  • 打赏
  • 举报
回复
兄弟,你不给chenwc(海市蜃楼) 分的话,我都觉得冤枉!哈哈。
hzslx 2003-02-19
  • 打赏
  • 举报
回复
谢谢!
路人陈 2003-02-19
  • 打赏
  • 举报
回复
使用API函数ShellExecute即可
HINSTANCE ShellExecute(

HWND hwnd, // handle to parent window
LPCTSTR lpOperation, // pointer to string that specifies operation to perform
LPCTSTR lpFile, // pointer to filename or folder name string
LPCTSTR lpParameters, // pointer to string that specifies executable-file parameters
LPCTSTR lpDirectory, // pointer to string that specifies default directory
INT nShowCmd // whether file is shown when opened
);


Parameters

hwnd

Specifies a parent window. This window receives any message boxes that an application produces. For example, an application may report an error by producing a message box.

lpOperation

Pointer to a null-terminated string that specifies the operation to perform. The following operation strings are valid:

String Meaning
"open" The function opens the file specified by lpFile. The file can be an executable file or a document file. The file can be a folder to open.
"print" The function prints the file specified by lpFile. The file should be a document file. If the file is an executable file, the function opens the file, as if "open" had been specified.
"explore" The function explores the folder specified by lpFile.


The lpOperation parameter can be NULL. In that case, the function opens the file specified by lpFile.

lpFile

Pointer to a null-terminated string that specifies the file to open or print or the folder to open or explore. The function can open an executable file or a document file. The function can print a document file.

lpParameters

If lpFile specifies an executable file, lpParameters is a pointer to a null-terminated string that specifies parameters to be passed to the application.
If lpFile specifies a document file, lpParameters should be NULL.

lpDirectory

Pointer to a null-terminated string that specifies the default directory.

nShowCmd

If lpFile specifies an executable file, nShowCmd specifies how the application is to be shown when it is opened. This parameter can be one of the following values:

Value Meaning
SW_HIDE Hides the window and activates another window.
SW_MAXIMIZE Maximizes the specified window.
SW_MINIMIZE Minimizes the specified window and activates the next top-level window in the Z order.
SW_RESTORE Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when restoring a minimized window.
SW_SHOW Activates the window and displays it in its current size and position.
SW_SHOWDEFAULT Sets the show state based on the SW_ flag specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application. An application should call ShowWindow with this flag to set the initial show state of its main window.
SW_SHOWMAXIMIZED Activates the window and displays it as a maximized window.
SW_SHOWMINIMIZED Activates the window and displays it as a minimized window.
SW_SHOWMINNOACTIVE Displays the window as a minimized window. The active window remains active.
SW_SHOWNA Displays the window in its current state. The active window remains active.
SW_SHOWNOACTIVATE Displays a window in its most recent size and position. The active window remains active.
SW_SHOWNORMAL Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when displaying the window for the first time.


If lpFile specifies a document file, nShowCmd should be zero.



Return Values

If the function succeeds, the return value is the instance handle of the application that was run, or the handle of a dynamic data exchange (DDE) server application.
If the function fails, the return value is an error value that is less than or equal to 32. The following table lists these error values:

Value Meaning
0 The operating system is out of memory or resources.
ERROR_FILE_NOT_FOUND The specified file was not found.
ERROR_PATH_NOT_FOUND The specified path was not found.
ERROR_BAD_FORMAT The .EXE file is invalid (non-Win32 .EXE or error in .EXE image).
SE_ERR_ACCESSDENIED The operating system denied access to the specified file.
SE_ERR_ASSOCINCOMPLETE The filename association is incomplete or invalid.
SE_ERR_DDEBUSY The DDE transaction could not be completed because other DDE transactions were being processed.
SE_ERR_DDEFAIL The DDE transaction failed.
SE_ERR_DDETIMEOUT The DDE transaction could not be completed because the request timed out.
SE_ERR_DLLNOTFOUND The specified dynamic-link library was not found.
SE_ERR_FNF The specified file was not found.
SE_ERR_NOASSOC There is no application associated with the given filename extension.
SE_ERR_OOM There was not enough memory to complete the operation.
SE_ERR_PNF The specified path was not found.
SE_ERR_SHARE A sharing violation occurred.

743

社区成员

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

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