views:

51

answers:

3

Hi,

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
A: 

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.

Rawheiser
Thanks for the suggestion but it doesn't seem to make any difference when using the blob to string conversion in any of the available encoding types.
klennepette
+1  A: 

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

Terry
Thanks for the input, you're right, I've tested this and the TypeText function does print the newlines correctly. I used Selection.GoTo to go to the form field's bookmark before using TypeText however it overwrites the entire form field with the text. And also throws an error if the document is protected. I'm gonna mess around with it a bit further, at least I have something to fall back on now :-)
klennepette
A: 

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".

Slapout
Thanks for the reply, the project is behind me now though. I did end up with dropping the entire form thing and just going with TypeText.
klennepette