We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Styles not kept in final document

In my application I upload a word document which is used as a template document into which I do a MailMerge and next some work with the document builder. None of the styles in the document template are changed (Heading1, 2 and 3 all have the font Cambria in different sizes).

In the document builder part I set the ParagraphFormat.StyleIdentifier to Heading1, 2, 3 or Normal.

The trouble is that in the final document the Heading styles have been changed into Times New Roman.

Any hints?

Hi Morten,

Thanks for your inquiry. It would be great if you please share following detail for investigation purposes.

  • Please attach your input Word documents.
  • Please

create a standalone/runnable simple application (for example a Console
Application Project
) that demonstrates the code you used to generate
your output document

  • Please attach the output Word file that shows the undesired behavior.
  • Please
    attach your target Word document showing the desired behavior. You can
    use Microsoft Word to create your target Word document. I will
    investigate as to how you are expecting your final document be generated
    like.

Unfortunately,
it is difficult to say what the problem is without the Document(s) and
simplified application. We need your Document(s) and simple project to
reproduce the problem. As soon as you get these pieces of information to
us we’ll start our investigation into your issue.

Hi Tahir
thanks for your reply.
I have attached a web project that displays my problem.
Included in the project root:

  • template.docx (the template document that is being worked on before saved into a new doc).
  • finished_document.doc (the document produced by the code in webform1.aspx.vb).
  • 2 screen shots showing the Heading 1 style in the template.docx and the changed Heading 1 style in the finished document.

Please let me know your findings.

/Morten

Hi Morten,

Please accept my apologies for late response.

Thanks for sharing the documents. I have tested the scenario and have manged to reproduce the same issue at my side. For the sake of correction, I have logged this problem in our issue tracking system as WORDSNET-9409. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

I’ve just upgrade to v13.12 and done a few more tests. The issue persists.

It turns out that the style trouble only occur when I use docBuilder.InsertHtml.
If I comment out line 31 in WebForm1.aspx.vb the style is applied correctly.

As a work-a-round I’m wondering if I can read and save the properties of Heading1 in a local variable and, after the docBuilder insertHtml, iterate over all heading1 headers and re-apply the original style?

The code works as it should in version both 13.8 and 13.9.
It’s version 13.10 that introduces the issue.

Hi Morten,

Thanks for your inquiry.

*mortenma:

I’ve just upgrade to v13.12 and done a few more tests. The issue persists.
It turns out that the style trouble only occur when I use docBuilder.InsertHtml.
If I comment out line 31 in WebForm1.aspx.vb the style is applied correctly.*

The DocumentBuilder.InsertHtml affect formatting of style Heading 1. This issue has not fixed in latest version of Aspose.Words v13.12.0. We will update you via this forum thread once this issue is resolved.

*mortenma:

As a work-a-round I’m wondering if I can read and save the properties of Heading1 in a local variable and, after the docBuilder insertHtml, iterate over all heading1 headers and re-apply the original style?*

Unfortunately, there is no perfect workaround available for this issue. This issue change the Heading styles (font name/size). However, please try the following workaround at your end (see the highlighted code). Hope this helps you.

Dim lDocumentTemplate As
New Document(MyDir
& "template.docx")
' merge values info fields
Dim lMergeFields As String() = {"mergeField1"}
Dim lMergeFieldValues As String() = {"testvalue for mergeField1"}
lDocumentTemplate.MailMerge.Execute(lMergeFields, lMergeFieldValues)
' do a little builder work 
Dim paragraphs As New List(Of String)
paragraphs.Add("first header with style set programatically")
paragraphs.Add("second heade with style set programaticallyr")
paragraphs.Add("third header with style set programatically")
Dim lDocumentBuilder As DocumentBuilder = New DocumentBuilder(lDocumentTemplate)
lDocumentBuilder.MoveToMergeField("mergeField2")
Dim Style = lDocumentTemplate.Styles.AddCopy(lDocumentTemplate.Styles(StyleIdentifier.Heading1))
Style.Name = "Haeading 1"
For Each Paragraph As String In paragraphs
With lDocumentBuilder
.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1
.Writeln(Paragraph)
Dim para As Paragraph = DirectCast(lDocumentBuilder.CurrentParagraph.PreviousSibling, Paragraph)
.ParagraphFormat.StyleIdentifier = StyleIdentifier.Normal
.InsertHtml("
normal text body
")
.Writeln("")
para.ParagraphFormat.ClearFormatting()
para.ParagraphFormat.Style = Style
End With
Next
lDocumentTemplate.UpdateFields()
lDocumentTemplate.Save(MyDir & "Out.docx")

*mortenma:

The code works as it should in version both 13.8 and 13.9.
It’s version 13.10 that introduces the issue.*

I have mentioned this detail in our issue tracking system for WORDSNET-9409. We will update you via this forum thread once this issue is resolved.

We appreciate your patience.

Does v14.1 resolve the issue WORDSNET-9409?

Hi Morten,

Thanks for your patience.

I am afraid your issue (WORDSNET-9409) has now been postponed till a later date due to some other important issues and new features. We will inform you as soon as there are any further developments.

We apologize for your inconvenience.

I see v14.2 does not solve WORDSNET-9409.
Any plans on when to fix the WORDSNET-9409 bug?

/Morten

Hi Morten,

Thanks for your inquiry. I would like to share with you that issues are addressed and resolved based on first come first serve basis. Currently, WORDSNET-9409 is pending for analysis and is in the queue. We will update you via this forum thread once there is any update available on your issue.

Thank you for your patience and understanding.

The issues you have found earlier (filed as WORDSNET-9409) have been fixed in this .NET update and this Java update.

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