The piece of code below converts a DOCX document into HTML, then merges sections of a document before converting it into another HTML file (tested with Aspose.Words 19.8.0.0
):
Dim doc As Words.Document = New Words.Document("D:\sample\sample.docx")
doc.Save("D:\sample\sample_html\sample.html")
' For some reasons two first ones won't be merged
For i As Integer = doc.Sections.Count - 2 To 0 Step -1
Dim s As Words.Section = doc.Sections.Item(i)
doc.LastSection.PrependContent(doc.Sections.Item(i))
s.Remove()
Next
doc.Save("D:\sample\sample_html_merged\sample_merged.html")
After a section merging, first bookmarks have been suffixed (_Toc49465255
→ _Toc49465255_0
):
- Before merging:
<h2 style="[...]">
<span style="[...]">1.1</span>
<span style="[...]"> </span>
<a name="_Toc49465255">
<span style="[...]">Lorem ipsum dolor sit amet, consectetur adipiscing elit</span>
</a>
</h2>
- After merging:
<h2 style="[...]">
<span style="[...]">1.1</span>
<span style="[...]"> </span>
<a name="_Toc49465255_0">
<span style="[...]">Lorem ipsum dolor sit amet, consectetur adipiscing elit</span>
</a>
</h2>
Why does this occur?
You’ll find the sample attached below.
Best regards.
sample.zip (44.6 KB)