[OfficeUtils] Remove line if placeholder text is blank

[OfficeUtils] Remove line if placeholder text is blank

  
Forge Component
(7)
Published on 21 Nov (2 weeks ago) by Elena Novozhilova
7 votes
Published on 21 Nov (2 weeks ago) by Elena Novozhilova
Hi,

very close to completion on this project (you'll be pleased to know) but I have an issue with the address on the word document.

We need to have the address displayed as:

Address1
Address2
Address3
Address4
County
Postcode

However not all fields will have a value but they don't want blank lines to appear in the address. Any ideas how I can overcome this?

Debra
What I do in cases like this is build a single field with carriage return characters in the correct places and if statements to skip the blank lines.  Something like this (the syntax might not be 100% correct as I did not test it).

Trim(Address1) + Chr(10) + If(Trim(Address2) <> "",Trim(Address2) + Chr(10),"") + If(Trim(Address3) <> "",Trim(Address3) + Chr(10),"") + If(Trim(Address4) <> "",Trim(Address4),"")

Hope this helps,
Curt
Hi Debra,

I think that Curt's suggestion is the way to go. I've tested it and it works perfectly.

Glad that you are getting to the finish line, and thanks for all your feedback, it provided the opportunity to improve the component a lot.

Bruno
Hi Bruno,

I got this to work as far as the text looking right but for some reason the placeholder doesn't pick this up.

I'm creating it as a new attribute within an aggregate

Registration.AddressLine1 + Chr(13) + 
If(Registration.AddressLine2 <> "",Registration.AddressLine2 + Chr(13),"") +
If(Registration.AddressLine3 <> "",Registration.AddressLine3 + Chr(13),"") +
If(Registration.AddressLine4 <> "",Registration.AddressLine4 + Chr(13),"") +
If(Registration.County <>"",Registration.County + Chr(13),"") +
If(Registration.Postcode <> "",Registration.Postcode,"")
When i debug I can see the output of the above be assigned to 'TextToMerge' but the placeholder just doesn't get replaced by it.
 
I'm going to do some further trouble shooting this afternoon though.

Debra
Hi Debra,

Try to rewrite the placeholder. Sometimes a chunk of text gets to be represented in the docx file content as more than one text run (e.g. "Pos" + "ition1") , and for the matchmaking with the placeholder to occur it has to be a single one. Fully rewrite the chunk of text usually solves the issues.

Also, on my test I used line feed (Chr(10)) and not carriage return (Chr(13)), so I'm not sure if carriage return will work.

Bruno
Hi Bruno,

I've made progress - the placeholder gets replaced now but not on separate lines. I have tried  Chr(10) and Chr(13).

I have attached screen shots of what it looks like in the debugger and how it appears on the page.

Debra


Hi Debra

I've been testing in LibreOffice since I don't have MS Office, so I guess it can  be a compatibility issue.

Can you send the exported file to my email so that I check if the address is presented properly in LibreOffice?

bruno.goncalves@gmail.com

Bruno
Hi Debra

In LibreOffice the address is displayed properly, so it is a compatibility issue.

I was already anticipating that this might happen so I changed the component to be more rubost, but it is not yet published on the Forge.

Just to make sure that this will work for you please access the following link, export the word file, and check if the section "Add Text" has 3 lines of text.

http://brunog.outsystemscloud.com/officeutilssample/

If everything is ok I will publish this new version on the Forge.

Bruno

Hi Bruno,

when i tried to open I got an error message to sya the file couldn't be opened and that the file is corrupt.

Debra

I made a fix in the meanwhile, please try it again Debra.

Bruno
Hi Bruno,

it opens and I see this

[Placeholder2 replaced - Line 1]
[Placeholder2 replaced - Line 2]
[Placeholder2 replaced - Line 3]

Debra
Perfect, what I was hoping to get.

I will publish the new version of the component that includes the fix for line separators. For this to work you must use line feed ( Char(10) ) as line separator. 

Bruno
Excellent

Thank you so much

Debra