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

  • SEARCH
  • Home
  • 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 8048329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:23:50+00:00 2026-06-05T06:23:50+00:00

I am trying to create the word document using the HWPFDocument . I am

  • 0

I am trying to create the word document using the HWPFDocument . I am able to create the doc with some feature but not able to get few things. My problem is simple but i am not able to figure out few things .
I want to convert this simple HTML into created worddoc :

<div xmlns="http://www.w3.org/1999/xhtml" class="formatted_content">
        <strong>cloudHQ.tester.4</strong> –
      this is the bold text
      <br/>
      this is italic text
      <br/>
      <ul>
      <li>bullets 1</li>
      <li>bullets 2</li>
      <li>bullets 3</li>
      </ul>
      <br/>
      <ol>
                <li>Number1</li>
                <li>Number2</li>
                <li>Number3</li>
      </ol>
      <br/>
      <pre>this is simple quote</pre>
      <br>
      this is simple quote
</div>

Here I am able to convert the bold and italic text . But not able to figure-out that how to create the

1) <ul><li>....
2) <ol><li>...
3) break <br>
4) <pre> 

tags into the WordDoc.

Is there is any example to do this , then please let me know
I really appreciate the efforts , thanks in advance.

Edited :

included library :

  include_class "org.apache.poi.poifs.filesystem.POIFSFileSystem"
  include_class "org.apache.poi.hwpf.usermodel.ParagraphProperties"
  include_class "org.apache.poi.hwpf.usermodel.CharacterRun"
  include_class "org.apache.poi.hwpf.usermodel.CharacterProperties"

And this is main code to convert the html to doc like :

 def convert_from_html_to_doc(html_file_name, comment_files)

    puts("Script start.....")
    puts("Parsing document comments start.....NEW")

    default_file = "misc/poi_experiment/empty.doc"
    fs = JavaPoi::POIFSFileSystem.new(JavaPoi::FileInputStream.new(default_file))

    # Horrible word Document Format
    hwpfDocument = JavaPoi::HWPFDocument.new(fs)

    # range is used for getting the range of the document except header and footer
    range = hwpfDocument.getRange()

    par1 = range.insertAfter(JavaPoi::ParagraphProperties.new(), 0)
    par1.setSpacingAfter(200);

    puts("Adding given html content to doc.")
    main_html = Nokogiri::HTML(File.read(html_file_name))
    characterRun = par1.insertAfter(main_html.text)
    # setting the font size
    characterRun.setFontSize(2 * 12)

    puts("Start procees on comment..... total : #{comment_files.size}")
    comment_files.each do |cf|

      file_path = "misc/poi_experiment/#{cf}"
      puts("The comment file path : #{file_path}")

      html = Nokogiri::HTML(File.read(file_path)).css('html')
      puts( html )

      par = characterRun.insertAfter(JavaPoi::ParagraphProperties.new(), 0)
      par.setSpacingAfter(200);

      #text = "<b><u>this is bold and underlined text</u></b>"
      text = html.to_s.scan(/\D\d*/)
      index = 0
      currentCharacterRun , currentCharacterStyleList = [], []
      character_arr = text.to_s.scan(/\D\d*/)

      character_or_tag, index = get_next_character_or_tag(character_arr, index)

      while !character_or_tag.nil?
       if character_or_tag.is_char?
        currentCharacterRun << character_or_tag.get_char
       end
       if character_or_tag.is_start_tag?
        currentCharacterRunText = currentCharacterRun.join
        if currentCharacterRunText != ""
          characterproperties = JavaPoi::CharacterProperties.new
          characterproperties = emit_to_document_and_apply_style(characterproperties, currentCharacterStyleList)
          characterRun = par.insertAfter(currentCharacterRunText,characterproperties)
          currentCharacterRun = []
        end
        currentCharacterStyleList << character_or_tag.get_tag
       end
       if character_or_tag.is_end_tag?
        currentCharacterRunText = currentCharacterRun.join
        if currentCharacterRunText != ""
          characterproperties = JavaPoi::CharacterProperties.new
          characterproperties = emit_to_document_and_apply_style(characterproperties, currentCharacterStyleList)
          characterRun = par.insertAfter(currentCharacterRunText,characterproperties)
          currentCharacterRun = []
        end
        currentCharacterStyleList.reject! { |x| x == character_or_tag.get_tag.gsub("/","") }
       end

       character_or_tag, index = get_next_character_or_tag(character_arr, index)
      end
    end

    hwpfDocument.write(JavaPoi::FileOutputStream.new("#{html_file_name}.doc", true))
  end

Hope this will help to understand you .

  • 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-06-05T06:23:52+00:00Added an answer on June 5, 2026 at 6:23 am

    After a lot of try I thought to move on jod converter

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

Sidebar

Related Questions

HI, I'm trying to create a word document in C++ using OpenXML SDK, I'm
I am trying to add bookmarks in word document using C# but it doesn't
I'm trying to create a word search game (kind of like Wordament but much
I'm trying to embed a PDF file into a Word document using the OLE
I am trying to create a Word document with a very simple word macro.
I am trying to create a word document from a java application and am
Using the OpenXML SDK, 2.0 CTP, I am trying to programmatically create a Word
I am trying to using Word Automation to save a document to a network
I'm trying to serve a word document (docx) from an asp.net page using the
I am trying to generate word documents using the mail merge feature in Microsoft

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.