When adding a table in word document font size is not kept

Hello,

This is regarding the issue WORDSNET-17186 (ticket When adding a table in word document font size and name is not kept).

I have tested the releases 18.9, 19.1 and 19.4 and the issue has fixed only half. Now the font name is passed correctly but the font size is incorrect. Instead of Calibri 11 it passes Calibri 10.

I have reattached the project.

In the attachment, there is a project that reproduces the issue. If you put the DLL files in “Aspose Check\WebApplication2\Aspose” folder the table from the second page from the output file “Aspose Check\WebApplication2\File\Test.docx” will have the incorrect format.

Thank you.Aspose Check.zip (508.6 KB)

@adrian.anton

Please note that Aspose.Words mimics the behavior of MS Word. If you join the documents with source formatting using MS Word, you will get the same output.

In your case, we suggest you please use ImportFormatMode as UseDestinationStyles to get the desired output.

Hello,

In the “TableDocument.docx” the table is formatted as Calibri (11) but in the final document is Calibri(10).

Version 17.4 does not have this issue.
We require to pass in the final document the same Font and Size from the source document. So in the final document, the table should be formated as Calibri (11).

Regards.

@adrian.anton

In this case, it was a bug in old version of Aspose.Words that has been fixed in the later version.

This is not a bug. You are facing the expected behavior of Aspose.Words. Please use ImportFormatMode.UseDestinationStyles in your code to get the font Calibri (11).

Hello,

As the documentation states the “KeepSourceFormatting” option does not preserve the style from the source document.

The “UseDestinationStyles”, does not enforce the exact style that is in the source document.
Our requirement is the following:

We have 2 documents with 2 completely different style in each of them. We need to create a third document with the exact styling form both documents.

If the first document is Calibri(10) and the second is Calibri(11), the destination document must have Calibri(10) and Calibri(11).

When using the UseDestinationStyles option, if a matching style already exists in the destination document, the style is not copied and the imported nodes are updated to reference the existing style.

The drawback of using UseDestinationStyles is that the imported text might look different in the destination document comparing to the source document. For example, the “Heading 1” style in the source document uses Arial 16pt font and the “Heading 1” style in the destination document uses Times New Roman 14pt font. When importing text of “Heading 1” style with no other direct formatting, it will appear as Times New Roman 14pt font in the destination document.

Using the KeepSourceFormatting option allows to make sure the imported text looks in the destination document exactly like it was in the source document. If a matching style already exists in the destination document, the source style is copied and given a unique name by appending a suffix number to it, for example “Normal_0” or “Heading 1_5”.

The drawback of using KeepSourceFormatting is that if you perform several imports, you could end up with many styles in the destination document and that could make using consistent style formatting in Microsoft Word difficult for this document.

Using KeepDifferentStyles option allows to reuse destination styles if the formatting they provide is identical to the styles in the source document. If the style in destination document is different from the source then it is imported.

@adrian.anton

Please note that formatting is applied on a few different levels. For example, let’s consider formatting of simple text. Text in documents is represented by Run element and a Run can only be a child of a Paragraph. You can apply formatting

  1. to Run nodes by using Character Styles e.g. a Glyph Style .
  2. to the parent of those Run nodes i.e. a Paragraph node ( possibly via paragraph Styles ).
  3. you can also apply direct formatting to Run nodes by using Run attributes ( Font ). In this case the Run will inherit formatting of Paragraph Style, a Glyph Style and then direct formatting.

In your case, direct formatting is applied to table’s text that is Calibri, (Latin) 11 pt, Black. This formatting is converted to Normal style in the destination document when you copy the content using MS Word. Aspose.Words does the same.

If a style is applied to table’s text e.g. Heading 1 or Normal, you will get the styles in output document according to ImportFormatMode.