无法使用 Powebuilder OLE 在 msword 表单字段中插入换行符

发布于 2024-09-09 23:08:20 字数 1401 浏览 13 评论 0原文

我有一个用 Powerbuilder 11.5 编写的应用程序,可以自动填充 Word 文档 (MS Word 2003) 的表单字段。

Word 文档受到保护,因此只能更改表单字段。

在下面的代码中,您可以看到我使用 char(10) + char(13) 插入换行符,但是在保存的文档中,我看到的只是字符应在的位置的 2 个小方块。
我也尝试过使用 "~r~n",这也只打印 2 个方块。

当我手动填写表单时,我可以根据需要插入换行符。

还有什么我可以尝试的吗?或者有人知道使用 Powerbuilder 填写单词表格的不同方法吗?

//1 Shipper
ls_value = ids_form_info.object.shipper_name[1]

if not isnull(ids_form_info.object.shipper_address2[1]) then
 ls_value += char(10) + char(13) + ids_form_info.object.shipper_address2[1]
end if

if not isnull(ids_form_info.object.shipper_address4[1]) then
 ls_value += char(10) + char(13) + ids_form_info.object.shipper_address4[1]
end if

if not isnull(ids_form_info.object.shipper_country[1]) then
 ls_value += char(10) + char(13) + ids_form_info.object.shipper_country[1]
end if

if lnv_word.f_inserttextatbookmark( 'shipper', ls_value ) = -1 then return -1

f_inserttextatbookmark如下:

public function integer f_inserttextatbookmark (string as_bookmark, string as_text, string as_fontname, integer ai_fontsize);
if isnull(as_text) then return 0
    iole_word = create OLEOBJECT

    iole_word.connectToNewobject( "word.application" )

    iole_word.Documents.open( <string to word doc> )

 iole_word.ActiveDocument.FormFields.Item(as_bookmark).Result = as_text

return 1
end function

I have an application written in Powerbuilder 11.5 that automatically fills in form fields of a Word document (MS Word 2003).

The Word document is protected so only the form fields can be altered.

In the code below you can see I use char(10) + char(13) to insert a newline, however in the saved document all I see is 2 little squares where the characters should be.
I've also tried using "~r~n", this also just prints 2 squares.

When I fill in the form manually I can insert newlines as much as I want.

Is there anything else I can try? Or does anybody know of a different way to fill in word forms using Powerbuilder?

//1 Shipper
ls_value = ids_form_info.object.shipper_name[1]

if not isnull(ids_form_info.object.shipper_address2[1]) then
 ls_value += char(10) + char(13) + ids_form_info.object.shipper_address2[1]
end if

if not isnull(ids_form_info.object.shipper_address4[1]) then
 ls_value += char(10) + char(13) + ids_form_info.object.shipper_address4[1]
end if

if not isnull(ids_form_info.object.shipper_country[1]) then
 ls_value += char(10) + char(13) + ids_form_info.object.shipper_country[1]
end if

if lnv_word.f_inserttextatbookmark( 'shipper', ls_value ) = -1 then return -1

The f_inserttextatbookmark is as follows:

public function integer f_inserttextatbookmark (string as_bookmark, string as_text, string as_fontname, integer ai_fontsize);
if isnull(as_text) then return 0
    iole_word = create OLEOBJECT

    iole_word.connectToNewobject( "word.application" )

    iole_word.Documents.open( <string to word doc> )

 iole_word.ActiveDocument.FormFields.Item(as_bookmark).Result = as_text

return 1
end function

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

离不开的别离 2024-09-16 23:08:20

您的问题的一部分是回车符是 char(13),换行符是 char(10),因此要在 Windows 和 DOS 中创建 CRLF,您通常需要创建 char(13) + char(10)。如果这些不正常,许多程序就会停止运行。然而,“~r~n”应该已经为你生成了它。

我已经成功了(为了简洁起见,我进行了转换,因此可能只能接近来纠正):

lole_Word.ConnectToNewObject ("Word.Application")
...
lole_Word.Selection.TypeText (ls_StringForWord)

也许您可以尝试其他Word OLE命令,看看它是否与特定命令有关。 (在定义换行符之后,我抓住了救命稻草。)

祝你好运,

特里

Part of your problem is that carriage return is char(13), and line feed is char(10), so to make a CRLF in Windows and DOS you usually need to make char(13) + char(10). If these are out of order, many programs will balk. However, "~r~n" should have produced that for you.

I have success with (and I'm converting for brevity so it might only be close to correct):

lole_Word.ConnectToNewObject ("Word.Application")
...
lole_Word.Selection.TypeText (ls_StringForWord)

Maybe you can try other Word OLE commands to see if it's something to do with the specific command. (After the definition of the line break, I'm grasping at straws.)

Good luck,

Terry

愛上了 2024-09-16 23:08:20

听起来这可能是 Unicode/Ansi 字符转换的事情。

对于它的价值,你可以尝试这个...

http://www.rgagnon.com /pbdetails/pb-0263.html

希望有帮助。

Sounds like it may be a Unicode/Ansi character conversion thing.

for what its worth you could try this ...

http://www.rgagnon.com/pbdetails/pb-0263.html

Hope it helps.

你的他你的她 2024-09-16 23:08:20

我没有使用表单字段,但我可以使用 TypeText 和“~n”将换行符从 PowerBuilder 插入到 Word 文档中。也许你只需要“~n”。

I'm not using form fields, but I am able to insert newlines into a Word document from PowerBuilder using TypeText and "~n". Maybe you just need "~n".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文