Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there any way to display line breaks , order list with using HWPFDocument
    primarykey
    data
    text
    <p>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 :</p> <pre><code>&lt;div xmlns="http://www.w3.org/1999/xhtml" class="formatted_content"&gt; &lt;strong&gt;cloudHQ.tester.4&lt;/strong&gt; – this is the bold text &lt;br/&gt; this is italic text &lt;br/&gt; &lt;ul&gt; &lt;li&gt;bullets 1&lt;/li&gt; &lt;li&gt;bullets 2&lt;/li&gt; &lt;li&gt;bullets 3&lt;/li&gt; &lt;/ul&gt; &lt;br/&gt; &lt;ol&gt; &lt;li&gt;Number1&lt;/li&gt; &lt;li&gt;Number2&lt;/li&gt; &lt;li&gt;Number3&lt;/li&gt; &lt;/ol&gt; &lt;br/&gt; &lt;pre&gt;this is simple quote&lt;/pre&gt; &lt;br&gt; this is simple quote &lt;/div&gt; </code></pre> <p>Here I am able to convert the bold and italic text . But not able to figure-out that how to create the</p> <pre><code>1) &lt;ul&gt;&lt;li&gt;.... 2) &lt;ol&gt;&lt;li&gt;... 3) break &lt;br&gt; 4) &lt;pre&gt; </code></pre> <p>tags into the WordDoc.</p> <p>Is there is any example to do this , then please let me know I really appreciate the efforts , thanks in advance.</p> <p><strong>Edited :</strong></p> <p>included library :</p> <pre><code> 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" </code></pre> <p>And this is main code to convert the html to doc like :</p> <pre><code> 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 = "&lt;b&gt;&lt;u&gt;this is bold and underlined text&lt;/u&gt;&lt;/b&gt;" 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 &lt;&lt; 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 &lt;&lt; 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 </code></pre> <p>Hope this will help to understand you .</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload