Update TOC Heading 3

I have an existing template. The TOC has a Heading 1 (Executive Summary), then another Heading 1 (Your Business Resource). I insert two templates under the second Heading 1 . Each template includes a Heading 3 that are numbered 1.1.1 and when aspose creates the doc, they still reflect 1.1.1 however they should get updated to this:

1 Executive Summary
2 Your Business Resource

2.1.1 Expedited Parcel
2.1.2 Regular Parcel

Can you provide an example in VB.Net (ASP.Net)?

Thanks!

Rob

01/15/2012 I have uploaded updated_toc.doc which is what it should look like (this file is slightly different). proposal.doc is the output generated by the code below via aspose.

This is what I have:

Dim dstDoc As New Document(Path.Combine(Request.PhysicalApplicationPath, “Documents\PDT.doc”))
Dim builder As New DocumentBuilder(dstDoc)

Dim srcDoc2 As New Document(Path.Combine(Request.PhysicalApplicationPath, “Documents\PD04-DOM-RegularParcel.doc”))
Dim srcDoc As New Document(Path.Combine(Request.PhysicalApplicationPath, “Documents\PD02-DOM-ExpeditedParcel.doc”))


‘’ Set the appended document to appear on the next page.
'Continuous tells word to append the new doc under a partial heading or paragraph
srcDoc.FirstSection.PageSetup.SectionStart = SectionStart.Continuous
srcDoc.FirstSection.PageSetup.RestartPageNumbering = False
dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting)

srcDoc2.FirstSection.PageSetup.SectionStart = SectionStart.Continuous
srcDoc2.FirstSection.PageSetup.RestartPageNumbering = False
dstDoc.AppendDocument(srcDoc2, ImportFormatMode.KeepSourceFormatting)

'update proposal title
'Move the insertion cursor to a merge field.
builder.MoveToMergeField(“Proposal_Title”)
builder.Write(“Best Buy”)

'Foot_Proposal_Title
builder.MoveToMergeField(“Foot_Proposal_Title”)
builder.Write(“Best Buy Proposal”)

builder.MoveToMergeField(“Address”)
builder.Write(“123 Anywhere St”)

builder.MoveToMergeField(“City”)
builder.Write(“Any City”)

builder.MoveToMergeField(“Prov”)
builder.Write(“ON”)

builder.MoveToMergeField(“Postal”)
builder.Write(“K0G1T0”)

builder.MoveToMergeField(“C_Company”)
builder.Write(“Best Buy Ltd”)

dstDoc.UpdateFields()
dstDoc.UpdatePageLayout()

dstDoc.Save(Path.Combine(Request.PhysicalApplicationPath, “Documents\proposal.doc”))

Hi Rob,


Thanks for your inquiry. Could you please attach your input Word document here for testing? I will investigate the issue on my side and provide you more information.

Files attached.

Hi Rob,


Thanks for sharing the document. You have shared the output document. To reproduce this issue, please share input documents which you have used in your code (PDT.doc, PD04-DOM-RegularParcel.doc and PD02-DOM-ExpeditedParcel.doc). I will investigate the issue on my side and provide you more information.

Files posted.

Hi Rob,


Thanks for sharing the documents. I have worked with your documents and have found that all document have different list styles with same name. E.g PDT.doc has style Heading 3 based on CPC Heading 2 List and PD02-DOM-ExpeditedParcel.doc has style Heading 3 based on Normal. Please see the attached images for detail.

In your case, I suggest you to use UseDestinationStyles in your code.

Please note that 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.

Thanks! That did the trick!

Hi Rob,


Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.