19
Views
5
Comments
Solved
[OfficeUtils] Word - Header and Text boxes
officeutils
Service icon
Forge asset by Bruno Gonçalves
Application Type
Service

I have a work around for these issues, but I'm interested to know if there is a fix for either.

After setting a Word Template and generating the Word file, my headers are automatically changed from 0" to 0.5".  I can change the template's headers to 0.5" in advance, but that makes the content of my Word doc more crowded.

I cannot change text within a text box from Word_Export_SetText, so I have to remove the text boxes from my templates.  

I am on v5.5

Thanks!

Simon Foster

UserImage.jpg
Bruno Gonçalves
Solution

Hi Simon, and sorry for the late reaction.

This is a very useful "catch". Thank you!

Contrary to the the "header top margin issue", this one can be fully addressed on the OfficeUtils side, without touching NPOI. So I will publishing a new version of OfficeUtils with the fix within the next couple of days.

Thanks again,

Bruno

UserImage.jpg
Bruno Gonçalves

Hi Simon,

I went to troubleshoot the header top margin issue, and concluded that between the template import and the document export NPOI (OfficeUtils underlying library) is loosing the margin setting. As a result, when one opens the exported document it applies the default top margin (0.5 inches). The only possibility to fix this is inside NPOIs implementation, and I will be assessing if I can do so.

Replacing text inside text boxes is expected to work, and it is even part of the "Set Text" example of "OfficeUtils Demo". Clearly there is something in your template I'm not accounting for, so it would be great if you could share the template for me to inspect it. Is it possible? You can of course anonymize it and remove most of the content. One "problematic" text box is all I need.

Best,

Bruno  

UserImage.jpg
Simon Foster

Hi Bruno,

Thank you so much for taking a look at these issues.  I've attached a file with everything removed except for two textboxes.  

TextBoxErrorNoBackground.docx
UserImage.jpg
Bruno Gonçalves

Hi Simon,

A couple of updates:

  • Header top margin: while looking at the NPOI implementation, it occurred to me "0" might be special case and treated differently from any non-zero margin value. Then I have tested a template with a very small margin value (0.1 cm) and confirmed that the export keeps it. I would suggest you to use this option as the practical effect is pretty much the same of using a "0".
  • Replace text in inside textboxes: I have looked inside the template you provided and everything looks pretty much as I would expect. In addition, I have run some tests where I was replacing a few of your template placeholders, and they were all successful. Not sure what can be the issue, but I would suggest two ways forward: 1) Update OfficeUtils to the latest version (5.6.0), and 2) review your logic to make sure the WordFile object is getting updated with the result of the different operations (e.g. Word_Export_SetText).

Hope this information helps.

Bruno 

UserImage.jpg
Simon Foster

Hi Bruno,

Thanks again for your help on these.  

Updates from me:

Header top margin: This worked! 

Replace text inside textboxes:  I did some more testing and the error comes from entering a null value into a text box.  Entering a null value works outside of a text box, but inside this throws a null value error.  

The workaround I applied is to add logic that enters chr(160) as a replacement for a null value.  Similar to the header issue, there is "something there" and the text replace works.

Thanks again!

UserImage.jpg
Bruno Gonçalves
Solution

Hi Simon, and sorry for the late reaction.

This is a very useful "catch". Thank you!

Contrary to the the "header top margin issue", this one can be fully addressed on the OfficeUtils side, without touching NPOI. So I will publishing a new version of OfficeUtils with the fix within the next couple of days.

Thanks again,

Bruno

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.