LINQ Reporting Engine: <<doc [document_expression] -sourceStyles>>

Hello,

We have had a support call where a customer is unable to keep the sourceStyles within the word document using the following syntax:

<<foreach [f in files]>><<doc[f.file] -sourceStyles>><</foreach>> (See the attachment for .docx)

application.docx (43.6 KB)

As far as we understand it, we would expect the .docx content to have red text once processed but that isn’t the case.

Is the switch syntax correct?

Thanks in advance for any help that you can provide.

@djsomers

Do you mean that text from a document being inserted should inherit the red font from your template? If so, then you should not use the sourceStyles switch, thus keeping formatting coming from the template. See Inserting Documents Dynamically for more information.

If something different is meant, please share more details. It would be great if you could share an example document being inserted as well as an expected result document created manually in MS Word.

@djsomers

We further looked into your document and it appears that red color of text in your template is not defined for a corresponding style, instead it is applied directly to text, so sourceStyles has nothing to do with it. As shared in my previous comment, please provide more details, so we could better understand your requirement.

Hi Ivan,

Thank you for the speedy response and sorry for only just getting back to you.

Please find attached the inputs (template and json) and the expected output that I have manually edited to show red text, which is the desired outcome in this instance.

Is that the wrong way to go about things? If so, what would the right approach be?

Thanks in advance.

Dan

Aspose.zip (388.8 KB)

@djsomers

We have made a deep investigation of your input template and data. At first, please let me share some explanations:

  1. There is some misunderstanding in how a doc tag works. Formatting of a document being inserted does not inherit formatting from a doc tag itself. Inserting Documents Dynamically does not mention that such an inheritance should take place.

  2. There is some misunderstanding in what -sourceStyles does. It affects only styles of a document, not direct formatting applied to text, which is also described in the abovementioned article.

All in all, there is no bug - both doc and -sourceStyles work as expected for your input template and data. That said, there is a recipe to get your desired output, but it is not so easy.

First of all, documents being inserted (provided in your JSON file) need to be modified. All direct formatting explicitly setting text color to black should be cleared and text color should be set to automatic. The same should be done for all styles in the documents. We have modified the first document being inserted in your JSON data file, so you could check how it should look like. Please check the modified document itself (in.docx - 25.5 KB) and the modified JSON data file (InputJson2.zip - 302.3 KB). The same procedure should be applied to the template document.

Then, you may choose one of the following options to proceed:

  1. Either do not use -sourceStyles and change styles in the template document, so that styles named the same as in documents being inserted use red text color (rather than automatic). Here is the modified template for this option - Input_Template_Modified.docx (32.3 KB). Please note that this option may affect other content in a result document, so use with caution.

  2. Or use textColor (see Setting Text Color Dynamically for details) in conjuction with doc. You may use or not use -sourceStyles in this case depending on your needs. Here is the modified template for this option - Input_Template_Modified2.docx (32.5 KB). Please note this option does not affect other content in a result document, so we would recommend this one, although the first one is also working.

When using the modified JSON file and one of the modified templates, a result document contains only its first part colored with red, because we have changed only the first document being inserted as decribed above to show the idea.

In case of any troubles, please feel free to ask.

Hi Ivan,

Thank you for the information.

Kind regards,

Daniel

1 Like