Saturday, 15 March 2014

Reading docx file by using Apache POI if the docx file contains image, paragraph, table -


How to read the doc file in the same order, if the document contains the image, paragraph and then the table. It is possible to read and add .docx files with the

Apache POI framework. You will need XWPF libraries and ooxml-schemas to do this. Here is an example of how to read a Microsoft Word file:

  Public Zero readonDocs file () throws IOException {InputStream inputStream = this.getClass (). GetClassLoader (). GetResourceAsStream ("template.docx"); XWPF document doc = new XWPF document (inputstream); // Article List & lt; XWPFParagraph & gt; Paragraph = doc.getParagraphs (); XWPF paragraph paragraph = paragraphs (1); // run list & lt; XWPFRun & gt; Run = paragraph.Gatoran (); XWPFRun run = runs.get (1); Run.setText ("some text"); Run.setFontSize (12); Run.setBold (true); //e.t.c. // Table List & lt; XWPFTable & gt; Table = doc.getTables (); XWPFTable table = tables.get (1); // line list & lt; XWPFTableRow & gt; Rows = table .getRows (); XWPFTableRow line = rows.get (1); // cell catalog & lt; XWPFTableCell & gt; Cells = row.getTableCells (); XWPTable cell cell = cellsGate (1); Cell.setText ("some text"); Cell.setParagraph (paragraph); //e.t.c. }  

You can create your own paragraph, run, table etc. Here is a good tutorial for the first step with XWPF:

For the picture, try reading byte with .getData () array, or with the inputstream Can work like getPackagePart (). GetInputStream ()

Then, byte array for one of your images - it seems that:


No comments:

Post a Comment