Cannot bring all the element from html to docx that have same tag with java -


i have project converting html docx java, in html document have 2 paragraph 2 header title, when converting both of them docx format, 1 paragraph converted, other paragraph doesn't converted have same tag. image below

click image detail

and code this

import java.io.file; import java.io.fileoutputstream; import java.util.list; import java.util.set; import static org.apache.poi.hslf.model.textproperties.textpropcollection.textproptype.paragraph; import org.apache.poi.openxml4j.opc.opcpackage; import org.apache.poi.xwpf.usermodel.verticalalign; import org.apache.poi.xwpf.usermodel.xwpfdocument; import org.apache.poi.xwpf.usermodel.xwpfparagraph; import org.apache.poi.xwpf.usermodel.xwpfrun; import org.zwobble.mammoth.documentconverter; import org.zwobble.mammoth.result;  /**  *  * @author alwan  */  public class testword {      /**      * @param args command line arguments      */     public static void main(string[] args) {         // todo code application logic here         try         {             file file = new file("src/test/test.docx");             documentconverter converter = new documentconverter();             result<string> result = converter.extractrawtext(file);             string html = result.getvalue(); // generated html             set<string> warnings = result.getwarnings(); // warnings during conversion              string[] part = html.split("<p>");             string[] part2 = html.split("<h1>");              fileoutputstream out = new fileoutputstream(new file("testformat.docx"));             xwpfdocument doc = new xwpfdocument();             xwpfparagraph paragraph = doc.createparagraph();              xwpfrun paragraphonerunone = paragraph.createrun();                          xwpfrun paragraphonerunthree = paragraph.createrun();                          (int = 0; < html.length(); i++)              {             if (i % 2 != 0)              {                           paragraphonerunone.setbold(true);                 paragraphonerunone.setitalic(true);                 paragraphonerunone.settext(part[i].trim());                 paragraphonerunone.addbreak();                  paragraphonerunthree.setstrike(true);                 paragraphonerunthree.setfontsize(20);                 paragraphonerunthree.setsubscript(verticalalign.subscript);                 paragraphonerunthree.settext(part2[i].trim());                  system.out.println(part2[i].trim());                 system.out.println(part[i].trim());                      doc.write(out);                     out.close();             }               system.out.println("testformat.docx written successully");             }             system.out.println("success");         } catch(exception e) {             e.printstacktrace();         }       }  } 

the question is, how bring paragraph html docx format when have same tag? thank attention before. sorry bad english


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -