Hi all,
I’m currently using DocumentBuilder.InsertHtml(...) to add content to a word document.
I control the html. Currently I’m using <h1> tags to designate headers. However, this doesn’t appear to convert to a heading tag in Word. I need my <h1> tags to be converted to word Headings so that they can be added to the Table of Contents. Do you know how I can do this?
@dwant can you please add the HTML that you are inserting, I ran the following code and I can’t replicate your problem:
// Initialize document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("TABLE OF CONTENTS");
// Insert a table of contents at the beginning of the document.
builder.InsertTableOfContents("\\o \"1-2\" \\h \\z \\u");
// Build a document with complex structure by applying different heading styles thus creating TOC entries.
for (int i = 1; i <= 10; i++)
{
// Inserting data which is a HTML
if(i%2 == 0)
{
builder.InsertHtml($"<h2>HEADER 2 {i} of 10</h2>");
}
else if(i%3 == 0)
{
builder.InsertHtml($"<h3>HEADER 3 {i} of 10</h3>");
}
else
{
builder.InsertBreak(BreakType.PageBreak);
builder.InsertHtml($"<h1>HEADER 1 {i} of 10</h1>");
}
builder.InsertHtml("<p>LOREM IPSUM DOLOR SIT AMET</p>");
}
// Update TOC
doc.UpdateFields();
// Save the document
doc.Save("C:\\Temp\\output.docx");
Additionally, you can insert HTML tags in the forum by formatting them as code using the editor toolbar or Markup formatting.
@dwant that’s weird I see it as heading, can you please post your output document, and the versions of Aspose.Words API and the MS Words application that you are using?
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.