List of usage examples for org.apache.poi.xwpf.usermodel XWPFTableCell getText
public String getText()
From source file:cn.afterturn.easypoi.word.parse.ParseWord07.java
License:Apache License
/** * ?/*from www .j a v a2 s.c o m*/ * * @return * @throws Exception * @author JueYue * 2013-11-18 */ private Object checkThisTableIsNeedIterator(XWPFTableCell cell, Map<String, Object> map) throws Exception { String text = cell.getText().trim(); // ? if (text != null && text.contains(FOREACH) && text.startsWith(START_STR)) { text = text.replace(FOREACH_NOT_CREATE, EMPTY).replace(FOREACH_AND_SHIFT, EMPTY).replace(FOREACH, EMPTY) .replace(START_STR, EMPTY); String[] keys = text.replaceAll("\\s{1,}", " ").trim().split(" "); return PoiPublicUtil.getParamsValue(keys[0], map); } return null; }
From source file:com.deepoove.poi.resolver.TemplateResolver.java
License:Apache License
@SuppressWarnings("unused") private static CellTemplate parseCell(XWPFTableCell cell) { if (null == cell) return null; String text = cell.getText(); if (null == text || "".equals(text.trim())) { return null; }/* w w w . j a v a2s . c om*/ return (CellTemplate) parseTemplateFactory(text, cell); }
From source file:com.qihang.winter.poi.word.parse.ParseWord07.java
License:Apache License
/** * ?//from w w w .j a v a2 s. c om * * @author Zerrion * @date 2013-11-18 * @return * @throws Exception */ private Object checkThisTableIsNeedIterator(XWPFTableCell cell, Map<String, Object> map) throws Exception { String text = cell.getText().trim(); // ? if (text.startsWith("{{") && text.endsWith("}}") && text.indexOf("in ") != -1) { return PoiPublicUtil.getRealValue(text.replace("in ", "").trim(), map); } return null; }
From source file:com.validation.manager.core.tool.table.extractor.TableExtractor.java
License:Apache License
private File writeTablesToFile() throws IOException { File temp = createTempFile("table", null); temp.createNewFile();/*from ww w . j av a 2s . com*/ temp.deleteOnExit(); List<DefaultTableModel> tables = new ArrayList<>(); for (XWPFTable table : extractTablesFromWord()) { //Build the table int rows = table.getNumberOfRows(); int columns = table.getRow(0).getTableCells().size(); Object[][] data = new Object[rows][columns]; String[] title = new String[columns]; for (int i = 0; i < columns; i++) { title[i] = format("Column {0}", i + 1); } //Row 0 for mapping field int rowNum = 0; int columnNum; for (XWPFTableRow row : table.getRows()) { columnNum = 0; for (XWPFTableCell cell : row.getTableCells()) { data[rowNum][columnNum] = cell.getText(); columnNum++; } rowNum++; } //Rebuild the table model to fit this table tables.add(new DefaultTableModel(data, title)); } FileOutputStream fileOut = null; ObjectOutputStream output = null; try { fileOut = new FileOutputStream(temp); output = new ObjectOutputStream(fileOut); output.writeObject(tables); output.flush(); } finally { if (output != null) { output.close(); } if (fileOut != null) { fileOut.close(); } } return temp; }
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()); }// www .j ava 2 s . c o 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(); } } }
From source file:kz.service.DocumentReader.java
public static String readDocxFile(String fileName) { try {//from w w w . j av a 2 s . c o m File file = new File(fileName); FileInputStream fis = new FileInputStream(file.getAbsolutePath()); StringBuffer content = new StringBuffer(); XWPFDocument document = new XWPFDocument(fis); XWPFStyles styles = document.getStyles(); List<XWPFParagraph> paragraphs = document.getParagraphs(); List<XWPFTable> tables = document.getTables(); List<XWPFPictureData> pictures = document.getAllPictures(); //int Picture_ID = 0; for (XWPFPictureData picture : pictures) { //XWPFPictureData picture = pictures.get(Picture_ID); System.out.println("Picture: " + picture.getFileName()); byte[] pictureData = picture.getData(); BufferedImage image = ImageIO.read(new ByteArrayInputStream(pictureData)); ImageIO.write(image, picture.getFileName(), file); content.append("<p>"); content.append("Here must be image"); content.append("</p>"); //Picture_ID++; } Iterator<IBodyElement> bodyElementIterator = document.getBodyElementsIterator(); int Table_ID = 0; int Paragraph_ID = 0; while (bodyElementIterator.hasNext()) { IBodyElement element = bodyElementIterator.next(); System.out.println(element.getElementType().name());//prints Element type name if ("TABLE".equalsIgnoreCase(element.getElementType().name())) { content.append("<table>"); XWPFTable table = tables.get(Table_ID); CTTbl cttbl = table.getCTTbl(); CTTblPr cttblPr = cttbl.getTblPr(); List<XWPFTableRow> tblRows = table.getRows(); for (XWPFTableRow tblRow : tblRows) { content.append("<tr>"); List<XWPFTableCell> tblCells = tblRow.getTableCells(); for (XWPFTableCell tblCell : tblCells) { content.append("<td>"); content.append(tblCell.getText()); content.append("</td>"); } content.append("</tr>"); } content.append("</table>"); Table_ID++; } else if ("PARAGRAPH".equalsIgnoreCase(element.getElementType().name())) { XWPFParagraph paragraph = paragraphs.get(Paragraph_ID); String styleClass = null; if (paragraph.getStyleID() != null) { content.append("<p class=''>"); XWPFStyle style = styles.getStyle(paragraph.getStyleID()); if (style != null && style.getName() != null) { //here will be code creation of tag with class style } } else { content.append("<p>"); } content.append(paragraph.getText()); content.append("</p>"); Paragraph_ID++; } } fis.close(); return content.toString(); } catch (Exception e) { return e.toString(); } }
From source file:myexamples.WordDocsExamples.Test1.java
public static void simplepartsReading() throws IOException { JFileChooser chooser = new JFileChooser(); if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { System.out.println(chooser.getSelectedFile().getName()); FileInputStream fis = new FileInputStream(chooser.getSelectedFile()); XWPFDocument doc = new XWPFDocument(fis); XWPFWordExtractor extract = new XWPFWordExtractor(doc); //System.out.println(extract.getText()); List<XWPFParagraph> pList = doc.getParagraphs(); List<XWPFTable> tList = doc.getTables(); System.out.println("Number of Paragraphs=" + pList.size()); System.out.println("Number of Tables=" + tList.size()); List<XWPFTableRow> rList; List<XWPFTableCell> cList; List<XWPFParagraph> rcpList; int tCount = 0, rCount = 0, cCount = 0, rcpCount = 0, dummCounter = 0; WordReference wordReference = new WordReference(); for (XWPFTable t : tList) { rList = t.getRows();// w w w .j av a2 s.co m rCount = 0; cCount = 0; rcpCount = 0; System.out.println("Table Nr." + (tCount++)); for (XWPFTableRow r : rList) { cList = r.getTableCells(); cCount = 0; rcpCount = 0; System.out.println("Row Nr." + (rCount++)); for (XWPFTableCell c : cList) { rcpList = c.getParagraphs(); rcpCount = 0; System.out.println("Cell Nr." + (cCount++)); System.out.println("Cell Text: " + c.getText()); System.out.println("Nr of Tables: " + c.getTables().size()); for (XWPFParagraph rcp : rcpList) { System.out.println("Par Nr." + (rcpCount++) + " Paragraphtext=" + rcp.getText()); } for (XWPFTable t1 : c.getTables()) { for (XWPFTableRow r1 : t1.getRows()) { for (XWPFTableCell c1 : r1.getTableCells()) { System.out.println("DC Nr." + dummCounter + " Cell Text: " + c1.getText()); switch (dummCounter) { case 0: wordReference.kundenLogo = c1.getText(); break; case 1: wordReference.kundenprofil = c1.getText(); break; case 2: wordReference.ausgangslage = c1.getText(); break; case 3: wordReference.losung = c1.getText(); break; case 4: wordReference.ergebnis = c1.getText(); break; case 5: wordReference.kunde = c1.getText(); break; case 6: wordReference.projektname = c1.getText(); break; case 7: wordReference.kundenstatement = c1.getText(); break; case 8: wordReference.statementBei = c1.getText(); break; case 9: wordReference.flisstext = c1.getText(); break; default: ; } dummCounter++; } } } } } } System.out.println(wordReference.toString(1)); } }
From source file:myexamples.WordDocsExamples.Test1.java
public static WordReference getWordReference() throws IOException { WordReference wordReference = new WordReference(); JFileChooser chooser = new JFileChooser(); if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { System.out.println(chooser.getSelectedFile().getName()); FileInputStream fis = new FileInputStream(chooser.getSelectedFile()); XWPFDocument doc = new XWPFDocument(fis); XWPFWordExtractor extract = new XWPFWordExtractor(doc); //System.out.println(extract.getText()); List<XWPFParagraph> pList = doc.getParagraphs(); List<XWPFTable> tList = doc.getTables(); // System.out.println("Number of Paragraphs="+pList.size()); // System.out.println("Number of Tables="+tList.size()); List<XWPFTableRow> rList; List<XWPFTableCell> cList; List<XWPFParagraph> rcpList; int tCount = 0, rCount = 0, cCount = 0, rcpCount = 0, dummCounter = 0; for (XWPFTable t : tList) { rList = t.getRows();//from w w w .j a v a2 s . c om rCount = 0; cCount = 0; rcpCount = 0; // System.out.println("Table Nr."+(tCount++)); for (XWPFTableRow r : rList) { cList = r.getTableCells(); cCount = 0; rcpCount = 0; // System.out.println("Row Nr."+(rCount++)); for (XWPFTableCell c : cList) { rcpList = c.getParagraphs(); rcpCount = 0; // System.out.println("Cell Nr."+(cCount++)); // System.out.println("Cell Text: "+c.getText()); // System.out.println("Nr of Tables: "+c.getTables().size()); for (XWPFParagraph rcp : rcpList) { // System.out.println("Par Nr."+(rcpCount++)+" Paragraphtext="+ rcp.getText()); } for (XWPFTable t1 : c.getTables()) { for (XWPFTableRow r1 : t1.getRows()) { for (XWPFTableCell c1 : r1.getTableCells()) { //System.out.println("DC Nr."+dummCounter+" Cell Text: "+c1.getText()); switch (dummCounter) { case 0: wordReference.kundenLogo = c1.getText(); break; case 1: wordReference.kundenprofil = c1.getText(); break; case 2: wordReference.ausgangslage = c1.getText(); break; case 3: wordReference.losung = c1.getText(); break; case 4: wordReference.ergebnis = c1.getText(); break; case 5: wordReference.kunde = c1.getText(); break; case 6: wordReference.projektname = c1.getText(); break; case 7: wordReference.kundenstatement = c1.getText(); break; case 8: wordReference.statementBei = c1.getText(); break; case 9: wordReference.flisstext = c1.getText(); break; default: ; } dummCounter++; } } } } } } //System.out.println(wordReference.toString(1)); } return wordReference; }
From source file:org.cgiar.ccafs.marlo.utils.POISummary.java
License:Open Source License
public void tableAStyle(XWPFTable table) { /* Horizontal merge, From format tables A */ CTVMerge vmerge = CTVMerge.Factory.newInstance(); CTVMerge vmerge1 = CTVMerge.Factory.newInstance(); for (int x = 0; x < table.getNumberOfRows(); x++) { if (x > 0) { XWPFTableRow row = table.getRow(x); for (int y = 0; y < 2; y++) { XWPFTableCell cell = row.getCell(y); if (cell.getCTTc() == null) { ((CTTc) cell).addNewTcPr(); }/*from w ww . j a v a2 s . c om*/ if (cell.getCTTc().getTcPr() == null) { cell.getCTTc().addNewTcPr(); } if (x == 1 && !(cell.getText().trim().length() > 0)) { break; } if (cell.getText().trim().length() > 0) { if (y == 0) { cell.getCTTc().getTcPr().addNewTcW().setW(BigInteger.valueOf(1500)); } vmerge.setVal(STMerge.RESTART); cell.getCTTc().getTcPr().setVMerge(vmerge); } else { if (y == 0) { cell.getCTTc().getTcPr().addNewTcW().setW(BigInteger.valueOf(1500)); } vmerge1.setVal(STMerge.CONTINUE); cell.getCTTc().getTcPr().setVMerge(vmerge1); } } } } }
From source file:org.cgiar.ccafs.marlo.utils.POISummary.java
License:Open Source License
public void tableBAnnualReportStyle(XWPFTable table) { /* Horizontal merge, From format tables B */ CTVMerge vmerge = CTVMerge.Factory.newInstance(); CTVMerge vmerge1 = CTVMerge.Factory.newInstance(); for (int x = 0; x < table.getNumberOfRows(); x++) { if (x > 0) { XWPFTableRow row = table.getRow(x); for (int y = 0; y < 2; y++) { XWPFTableCell cell = row.getCell(y); if (cell.getCTTc() == null) { ((CTTc) cell).addNewTcPr(); }/* www . j av a2s . com*/ if (cell.getCTTc().getTcPr() == null) { cell.getCTTc().addNewTcPr(); } if (x == 1 && !(cell.getText().trim().length() > 0)) { break; } if (cell.getText().trim().length() > 0) { if (y == 0) { cell.getCTTc().getTcPr().addNewTcW().setW(BigInteger.valueOf(1500)); } vmerge.setVal(STMerge.RESTART); cell.getCTTc().getTcPr().setVMerge(vmerge); } else { if (y == 0) { cell.getCTTc().getTcPr().addNewTcW().setW(BigInteger.valueOf(1500)); } vmerge1.setVal(STMerge.CONTINUE); cell.getCTTc().getTcPr().setVMerge(vmerge1); } } } } }