Themes and table styles not preserved as expected

Dear Aspose team!

By Aspose.Words version 6.5, it was announces that now preserving table styles and themes is supported for docx documents:
https://blog.aspose.com/category/words/

When inserting just one table into a document with body theme and Calibri font, by first impression it seems to work: the style is preserved and the document kept the body theme.

A more detailed look indicates, that inner table cells did not adopt the body theme; they are now without any theme and with having Times New Roman as font.

If we insert more than one tables, the behaviour becomes more confusing: just one table adopts the style while others lose their style.

Are this bugs / issues that are known to you?

If so, when would it be possible to receive fixes?

If not, what am I doing wrong?

Please let me know if you need further information.

Thank you very much for your help,

cheers,

Stephan

Hello Stephan!

Thank you for your inquiry.

At this stage I don’t see what you are doing wrong. Please attach sample document(s) that looses table styles and describe the scenarios (what you are doing with them). The more details you supply the faster we can help you with a solution.

Regards,

Hello!

Thanks for your reply!

I posted some sample files for my two problems:

1. "one table adopts the style while others lose their style"

Please find attached a few sample files in table_styles_get_lost_samples.zip.

Our scenario is:

We have a template named template.docx.

This template contains bookmarks which surround tables. These tables are removed and similar tables from the sample documents styled_tables1.docx and styled_tables2.docx are inserted into the bookmarks.

File template_after_inserting_tables.docx shows the result:

The first inserted table which is inserted into bookmark C2409Mod000000010002477R0000000004 seems to have lost its style.

The second table in template_after_inserting_tables.docx has not been overwritten; its style seems to be preserved as it should be.

The third table which was inserted at C8256Mod000000010005147R0000000005 has also lost its style.

The last two ones have not been manipulated (as the second one) and their styles seem to be preserved, too.

By drawing a conclusion, I can say that the tables that have been inserted from other documents lost their styles while the ones that have not been touched kept their styles.

2. "inner table cells did not adopt the body theme"

Please take a look at the attached inner_table_cells_lose_theme.zip :

We’ve got a template containing just an empty table. This template has the Calibry(Body) theme, see template.docx.

After inserting data into the table, we get template_after_inserting_table_data.docx .

Aa you can see, the inner table cells now have the Times New Roman Font (and no body theme).

I hope this helps, thanks a lot for your efforts!

Cheers,

Stephan

Hi again!

Thank you for sharing materials with our support.

I see the issues you are describing. Please also show the code that manipulates the documents – inserting tables from one documents to others. I suspect you are using Document.ImportNode method and it doesn’t preserve table styles referenced by importing tables.

Regards,

Hi Klepus!

Yes, you are right, I’m using

Node tempTextModuleNode = wordDoc.ImportNode(txmNode, true,
ImportFormatMode.KeepSourceFormatting);

Before inserting, I am checking if tempTextModuleNode is a Paragraph or a Table:

Tables are inserted as a whole into the target Body while a Paragraph’s children are inserted into a target Paragraph.

Is it possible or necessary to insert tables without importing them before?

Thanks again,

Stephan

Every node from one document should be imported before you insert it to another one. I’d like to see the full code fragment starting at the point you open the documents and ending where you save them. One line of code might not discover all the tricks.

Thank you,

Hi Viktor!

Please find attached doc_insertion_logic.txt.

This contains the code of our method

public static void InsertDocuments(Bookmark bookmark,
IList txmDocs,
IDictionary<Document, IList> documentToFormattersDictionary,
bool removeBookmark)

bookmarks is the bookmark, into which the text modules are inserted, txmDoc are the text modules, documentToFormattersDictionary contains a mapping to Node formatters and removeBookmark specifies if the insertions bookmark shall be removed after the module insertion.

I hope this helps to find out what my problem is.

Please let me know if you have any questions.

Thank you very much,

Stephan

Hi Stephan!

Thank you for your code. But it’s quite complex. It might take a long time for me to get it clear. Would you please simplify the code to some minimal sample that reproduces these issues with table formatting?

Regards,

Hi Viktor!

Yes sure :-), there is a lot of logic in there.

But currently, we are processing no formattings on tables when inserting them. Tables are inserted as they are. This is done by:

if (tempTextModuleNode is Table)
{
    currentInsertionNode = tempTextModuleNode;
    moduleInsertionEndNode.ParentNode.InsertBefore(currentInsertionNode, moduleInsertionEndNode);
    insertedTextModuleNodes.Add(currentInsertionNode);
    wasLastNodeTable = true;
}

Different from Paragraphs, Tables are inserted directly before moduleInsertionEndNode (usually the paragraph which contains the BookmarEnd) while Paragraph content is inserted by the Paragraph’s child nodes, using DocumentBuilder.

This affords a little bit more complex logic to arrange the original bookmark before inserting:

If the text modules to be inserted contain one ore more tables, bookmark start and bookmark end get each an own parent aragraph so that the table can be inserted between (for tables cannot be inserted directly into the original bookmark-paragraph).

As mentioned before, both, Paragraphs and Tables are imported by the target document before inserting.

I hoper this helps.

Thank you,

cheers,

Stephan

Thank you. I should have guessed that it’s enough to simply insert a table to an empty document. I have reproduced the issue trivially for both UseDestinationStyles and KeepSourceFormatting modes:

private static void TestInsertTable()
{
    Document src = new Document("insert_table/styled_tables1.docx");
    Node original = src.GetChild(NodeType.Table, 0, true);
    TestInsertTableOneMode(original, ImportFormatMode.UseDestinationStyles, "insert_table/result_UseDestinationStyles.docx");
    TestInsertTableOneMode(original, ImportFormatMode.KeepSourceFormatting, "insert_table/result_KeepSourceFormatting.docx");
}

private static void TestInsertTableOneMode(Node original, ImportFormatMode mode, string outFileName)
{
    Document dest = new Document();
    Node imported = dest.ImportNode(original, true, mode);
    dest.FirstSection.Body.AppendChild(imported);
    dest.Save(outFileName);
}

A new issue has been registered under reference number #9796. We’ll notify you when it’s fixed.

Best regards,

Hi Viktor!

Thanks for the information.

Could you please estimate when the issue probably is fixed?

Would the fix concern both problems, the preservation of table styles and the template themes?

Thank you,

cheers,

Stephan

Stephen,

I cannot estimate right now. This should be investigated. Table styles are still in development. They are not fully supported yet, at least preserved on import/export.

Regards,

The issues you have found earlier (filed as 9796) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.