Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6981803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:12:17+00:00 2026-05-27T18:12:17+00:00

I am using this library to convert an html text to word format. Everything

  • 0

I am using this library to convert an html text to word format.

Everything works perfectly.

I need to style some of the text now. what I am using right now to generate document is that I have a list of heading and sub headings and heading text, I am using for each loop to get heading and subheading and its text and output them but I want these heading and subheading to assign heading1 to category and heading2 to sub category. here is what I got so far:

Foreach loop to get catagories and sub categories with its text

foreach (var category in ct)
            {
                strDocumentText.Append(category.ParentCat.CategoryName);
                strDocumentText.Append("<br />");
                if(category.DocumentText != null)
                {
                    strDocumentText.Append(category.DocumentText);
                }

                if (category.Children != null)
                {
                    foreach (var subCategoreis in category.Children)
                    {
                        strDocumentText.Append("<p />");
                        strDocumentText.Append(subCategoreis.ParentCat.CategoryName);
                        strDocumentText.Append("<br />");
                        if (category.DocumentText != null)
                        {

                            strDocumentText.Append(subCategoreis.DocumentText);
                        }
                    }
                }

            }

Create word document :

StringBuilder strDocumentText = new StringBuilder();

string html = strDocumentText.ToString();
 using (MemoryStream generatedDocument = new MemoryStream())
                {
                    BuildDocument(generatedDocument, html);
                    using (WordprocessingDocument wordDoc = WordprocessingDocument.Create(generatedDocument, WordprocessingDocumentType.Document))
                    {
                         MainDocumentPart mainPart = wordDoc.MainDocumentPart;
                       if (mainPart == null)
                       {
                           mainPart = wordDoc.AddMainDocumentPart();
                           new DocumentFormat.OpenXml.Wordprocessing.Document(new Body()).Save(mainPart);
                       }

                       HtmlConverter converter = new HtmlConverter(mainPart);
                       Body body = mainPart.Document.Body;

                        var paragraphs = converter.Parse(html);
                        for (int i = 0; i < paragraphs.Count; i++)
                       {
                            body.Append(paragraphs[i]);
                       }

                        mainPart.Document.Save();
                    }

                    fs.Close();
                    File.WriteAllBytes(saveFileDialog1.FileName, generatedDocument.ToArray());
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:12:17+00:00Added an answer on May 27, 2026 at 6:12 pm

    First you need to add the style definitions to the document. The default styles are not included when constructing an OpenXml Document. After you define the styles, you can reference them in the paragraph properties element (serialized as “pPr”) OR the run element properties. Take a look at: http://msdn.microsoft.com/en-us/library/cc850838.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using TinyXML to parse/build XML files. Now, according to the documentation this library
I'm using this library to hook keys and I have some problems with comparing
We are using Tesseract's Java library, Called Tess4j to convert PDF files to text.
I need to convert HTML file to iXBRL format. iXBRL format is basically html
not using the C standard library do this in C++ ? Convert string to
I am currently developing a library and a set of programs using this library,
I've just solved another *I-though-I-was-using-this-version-of-a-library-but-apparently-my-app-server-has-already-loaded-an-older-version-of-this-library-*issue (sigh). Does anybody know a good way to verify
Since I have started using this site, I keep hearing about the Boost library.
We are using a third part library to render 3d. In this library there
I'm using a open-source Python library in my project. This library logs a lot

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.