Preserving word style template information while round triping

Aspose has been a really great product for us and we understand that all the information cannot be retained when we round trip from Word -> HTML -> We have been able to maintain most of the style information for our clients using Aspose.

One of our clients recently made a request whereby they want to be able to preserve the style template information that they use in the word after the round trip. So here is the sequence of events.

  1. Word document created with custom style templates (header, paragraph styles)
  2. Word document converted to HTML through Aspose.words for Java
  3. HTML document is then edited and converted back to Word through Aspose.words for Java

Now when they open the final word document they want to be able to see which template went where. Even though the style by themselves are preserved, the association to a custom template is lost.

Is there something that can be done here? I know I am shooting in the dark and I have gone through the forum and documentation and not found anything that can help us.

Thanks
Kamal

Hi
Thanks for your request. I think you can use AttachedTemplate:
https://reference.aspose.com/words/net/aspose.words/document/attachedtemplate/
You can save this value before converting document to HTML and restore it when converting it back to DOC.
Best regards.

Hi,

Attached Template is not working for me.

Our requirement is .doc -> .html -> .doc.
When I do .doc -> .html. I got the doc Template saved. Template extraction works fine.
But when I do .html + Template -> .doc, the Template is not picking up.

I also tried creating a Template from the document using word 2007.

And I also tried the .doc + Template -> .doc.
I have attached the document.
Am I missing some thing?

Following are the code fragments:

Document document = new Document(srcPath1);

document.isTemplate(true);

document.save(templatePath, SaveFormat.DOTX);

document.isTemplate(false);

document.save(htmlPath, SaveFormat.HTML);

Document document = new Document(srcDoc);
document.setAttachedTemplate(templateDoc);
document.save(docPath, SaveFormat.DOC);

–karthikeyan

Hi
Thanks for your request. Do you need that style names of each element in MS Word document will be preserved during DOC->HTML->DOC roundtrip? If so, unfortunately, currently there is no way to achieve that.
I think it would be possible when CSS styles will be supported during HTML import. For example if you try using embedded CSS styles when save your document to HTML:
doc.getSaveOptions().setHtmlExportCssStyleSheetType(CssStyleSheetType.EMBEDDED);
Names of CSS styles in HTML document will be the same as names of styles in the Word Document. Here is snippet of HTML:

HeadingSample1

This is a list paragraph and needs to be treated as such

HeadingSample2

But if you open such HTML using Aspose.Words, style names and formatting will be lost. CSS styles will be supported in one of future releases. Best regards.

Let me try to explain our requirements.

  1. We need to preserve the style and formatting (as much as we can) during the round trip of the document.
  2. The final word document when opened should have styles match up with the templates styles with which they were created.

From what I understand is that we can not have both currently.

Couple of quick questions then.

  1. For us to preserve formatting and style, you recommend that we don’t use embedded mode for CSS Style sheet?
  2. Do you have a time line or some estimate as to when you would be adding support to CSS styles in future?
  3. What does the setTemplate method on the document do then currently? Is my assumption correct that it does apply the template, it is the association of style with template that is lost?

Thanks
Kamal

Hi
Thanks for your request.

  1. Yes, you should use inline styles mode to preserve formatting during roundtrip.
  2. First this feature should be supported in .NET mainstream and next ported to Java. This could take quite a long time. Porting iteration usually takes 4 months or more. So current estimate is 4-6 months, but I cannot promise anything.
  3. setAttachedTemplate specifies the template attached to the document. So styles defined in this template will be available in the document.
    Theoretically, you can try parsing HTML and set styles of corresponding paragraphs in the document, but it require much of effort.
    Best regards.