List of usage examples for org.apache.poi.xwpf.usermodel XWPFDocument getTables
@Override
public List<XWPFTable> getTables()
From source file:apachepoitest.DocumentPropertyEnumerator.java
public static void showProperties(XWPFDocument docx) { List<XWPFParagraph> lp = docx.getParagraphs(); List<XWPFTable> lt = docx.getTables(); showParagraphProperties(lp);/* w ww. j ava 2 s . c o m*/ showTableProperties(lt); }
From source file:biz.webgate.dominoext.poi.component.kernel.DocumentProcessor.java
License:Apache License
public int processBookmarks2Document(XWPFDocument dxProcess, List<IDocumentBookmark> arrBookmarks) { // First Prozessing all paragraphs. for (XWPFParagraph paraCurrent : dxProcess.getParagraphs()) { processBookmarks2Paragraph(arrBookmarks, paraCurrent); }//from w ww .ja va2 s . c o m for (XWPFTable tabCurrent : dxProcess.getTables()) { processBookmarks2Table(arrBookmarks, tabCurrent); } for (XWPFHeader headCurrent : dxProcess.getHeaderList()) { for (XWPFParagraph paraCurrent : headCurrent.getParagraphs()) { processBookmarks2Paragraph(arrBookmarks, paraCurrent); } for (XWPFTable tabCurrent : headCurrent.getTables()) { processBookmarks2Table(arrBookmarks, tabCurrent); } } for (XWPFFooter footCurrent : dxProcess.getFooterList()) { for (XWPFParagraph paraCurrent : footCurrent.getParagraphs()) { processBookmarks2Paragraph(arrBookmarks, paraCurrent); } for (XWPFTable tabCurrent : footCurrent.getTables()) { processBookmarks2Table(arrBookmarks, tabCurrent); } } return 1; }
From source file:ch.admin.isb.hermes5.business.word.Docx4jWordDocumentCustomizerTest.java
License:Apache License
private Map<String, String> getTableMap(byte[] result) throws IOException { Map<String, String> map = new HashMap<String, String>(); XWPFDocument document = new XWPFDocument(new ByteArrayInputStream(result)); List<XWPFTable> tables = new ArrayList<XWPFTable>(); tables.addAll(document.getTables()); List<XWPFHeader> headers = document.getHeaderList(); for (XWPFHeader header : headers) { tables.addAll(header.getTables()); }//from www.j a v a2s. com for (XWPFTable xwpfTable : tables) { List<XWPFTableRow> rows = xwpfTable.getRows(); for (XWPFTableRow xwpfTableRow : rows) { List<XWPFTableCell> tableCells = xwpfTableRow.getTableCells(); if (tableCells.size() == 2) { map.put(tableCells.get(0).getText(), tableCells.get(1).getText()); } if (tableCells.size() == 1) { map.put(tableCells.get(0).getText(), ""); } } } return map; }
From source file:ch.admin.isb.hermes5.business.word.TranslationWordAdapter.java
License:Apache License
public List<TranslateableText> read(InputStream in, String docLang) { List<TranslateableText> result = new ArrayList<TranslateableText>(); XWPFDocument document = null; try {//from w w w .j ava 2s . c om document = new XWPFDocument(in); in.close(); } catch (IOException e) { throw new RuntimeException(e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } } List<XWPFTableRow> rows = document.getTables().get(0).getRows(); for (XWPFTableRow r : rows) { String[] identifiers = r.getCell(0).getText().split("\\/"); if (identifiers.length != 2) { throw new RuntimeException("Unable to parse identifier " + r.getCell(0).getText()); } TranslateableText text = new TranslateableText("", "", "", "", "", identifiers[0].trim(), identifiers[1].trim(), ""); if (docLang.equals("fr")) { text.setTextFr(r.getCell(1).getText()); } if (docLang.equals("it")) { text.setTextIt(r.getCell(1).getText()); } if (docLang.equals("en")) { text.setTextEn(r.getCell(1).getText()); } result.add(text); } return result; }
From source file:ch.admin.isb.hermes5.tools.translator.Translator.java
License:Apache License
public byte[] translateWordFile(InputStream in, String lang) { XWPFDocument document = null; try {//from ww w. ja v a2 s.c om document = new XWPFDocument(in); in.close(); } catch (IOException e) { throw new RuntimeException(e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } } List<XWPFTableRow> rows = document.getTables().get(0).getRows(); for (XWPFTableRow r : rows) { r.getCell(1).setText(lang + " " + lang); } try { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); document.write(outStream); return outStream.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:ch.admin.searchreplace.SearchReplaceTerms.java
License:Apache License
/** * Ersetzt eine Liste von Ausdruecken in einer Datei und schreibt das Resultat nach Output * @param input Inputdatei/*from w ww. j av a 2 s.com*/ * @param output Outputdatei * @param srTerms Begriff * @throws IOException I/O Fehler * @throws InvalidFormatException OpenXML Document korrupt * @throws FileNotFoundException Datei nicht vorhanden */ private static void searchReplaceInFile(String input, String output, HashMap<String, String> srTerms) throws IOException, InvalidFormatException, FileNotFoundException { XWPFDocument doc = new XWPFDocument(OPCPackage.open(input)); // Header List<XWPFHeader> header = doc.getHeaderList(); for (Iterator<XWPFHeader> e = header.iterator(); e.hasNext();) { XWPFHeader h = e.next(); for (XWPFParagraph p : h.getParagraphs()) { XWPFRun r = consolidateRuns(p); if (r != null) searchReplace(srTerms, r); } for (XWPFTable tbl : h.getTables()) for (XWPFTableRow row : tbl.getRows()) for (XWPFTableCell cell : row.getTableCells()) for (XWPFParagraph p : cell.getParagraphs()) { XWPFRun r = consolidateRuns(p); if (r != null) searchReplace(srTerms, r); } } // Document for (XWPFParagraph p : doc.getParagraphs()) { XWPFRun r = consolidateRuns(p); if (r != null) searchReplace(srTerms, r); } for (XWPFTable tbl : doc.getTables()) for (XWPFTableRow row : tbl.getRows()) for (XWPFTableCell cell : row.getTableCells()) for (XWPFParagraph p : cell.getParagraphs()) { XWPFRun r = consolidateRuns(p); if (r != null) searchReplace(srTerms, r); } doc.write(new FileOutputStream(output)); }
From source file:com.bxf.hradmin.testgen.service.impl.DocxTestGenerator.java
License:Open Source License
@Override public void generate(String versionOid, List<QuestionSnapshot> questions) { File docxFile = new File(getRootPath(versionOid), "T-Java.docx"); try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(docxFile)); InputStream is = TestGenerator.class.getResourceAsStream("/template/questions.docx")) { XWPFDocument doc = new XWPFDocument(is); replaceWordHolder(doc);/*from ww w .j a v a 2 s.c o m*/ XWPFTable table = doc.getTables().get(0); for (QuestionSnapshot question : questions) { XWPFTableRow row = table.createRow(); writeQuestionNo(question.getQuestionNo(), row); writeQuestion(question, row); } // template row table.removeRow(0); // setBorders(table); // doc.write(bos); File[] unzipFiles = { docxFile, new File(getRootPath(versionOid), "A-Java.txt") }; File destination = new File(getRootPath(versionOid), "T-Java-docx.zip"); ZipUtils.zip(destination, true, null, unzipFiles); } catch (IOException e) { log.error(e.getMessage(), e); throw new TestGenException(e.getMessage(), ModuleInfo.TestGenMgr); } }
From source file:com.raghav.plot.ReadDOCX.java
public static void main(String[] args) { InputStream in = null;/*w ww .ja v a 2 s .com*/ String result = ""; try { in = new FileInputStream(new File("/home/raghav/Desktop/Axis-LB.docx")); XWPFDocument doc = new XWPFDocument(in); doc.getParagraphs().stream().map((p) -> p.getRuns()).filter((runs) -> (runs != null)) .forEach((runs) -> { runs.stream().forEach((r) -> { String text = r.getText(0); System.out.println(text); }); }); doc.getTables().stream().forEach((tbl) -> { tbl.getRows().stream().forEach((row) -> { row.getTableCells().stream().forEach((cell) -> { cell.getParagraphs().stream().forEach((p) -> { p.getRuns().stream().filter((r) -> (r != null)).forEach((r) -> { String text = r.getText(0); if (text != null) { System.out.println(text); } }); }); }); }); }); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.validation.manager.core.tool.table.extractor.TableExtractor.java
License:Apache License
private List<XWPFTable> extractTablesFromWord() throws FileNotFoundException, IOException { List<XWPFTable> tables; try ( //Word documents InputStream fis = new FileInputStream(source)) { XWPFDocument doc = new XWPFDocument(fis); tables = doc.getTables(); }/*from w ww. ja v a 2 s . c o m*/ return tables; }
From source file:DocxProcess.ReadWordDocx.java
public void ReadByDocx(XWPFDocument doc) throws IOException { List<XWPFParagraph> paras = doc.getParagraphs(); System.out.println("Paragraph"); for (XWPFParagraph para : paras) { System.out.println(para.getText()); }//from w ww . ja v a2 s .co m List<XWPFTable> tables = doc.getTables(); List<XWPFTableRow> rows; List<XWPFTableCell> cells; System.out.println("TableCell"); for (XWPFTable table : tables) { rows = table.getRows(); for (XWPFTableRow row : rows) { System.out.println(""); cells = row.getTableCells(); for (XWPFTableCell cell : cells) { System.out.print(cell.getText()); System.out.print(" "); } System.out.println(); } } }