/** * 判断是不是迭代输出 * * @Author JueYue * @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; }
/** * 判断是不是迭代输出 * * @author JueYue * 2013-11-18 * @return * @throws Exception */ 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; }
/** * 解析参数行,获取参数列表 * * @Author JueYue * @date 2013-11-18 * @param currentRow * @return */ private static String[] parseCurrentRowGetParams(XWPFTableRow currentRow) { List<XWPFTableCell> cells = currentRow.getTableCells(); String[] params = new String[cells.size()]; String text; for (int i = 0; i < cells.size(); i++) { text = cells.get(i).getText(); params[i] = text == null ? "" : text.trim().replace("{{", "").replace("}}", ""); } return params; }
/** * 解析参数行,获取参数列表 * * @Author JueYue * @date 2013-11-18 * @param currentRow * @return */ private static String[] parseCurrentRowGetParams(XWPFTableRow currentRow) { List<XWPFTableCell> cells = currentRow.getTableCells(); String[] params = new String[cells.size()]; String text; for (int i = 0; i < cells.size(); i++) { text = cells.get(i).getText(); params[i] = text == null ? "" : text.trim().replace("{{", "").replace("}}", ""); } return params; }
/** * 解析参数行,获取参数列表 * * @author JueYue * 2013-11-18 * @param currentRow * @return */ private static String[] parseCurrentRowGetParams(XWPFTableRow currentRow) { List<XWPFTableCell> cells = currentRow.getTableCells(); String[] params = new String[cells.size()]; String text; for (int i = 0; i < cells.size(); i++) { text = cells.get(i).getText(); params[i] = text == null ? "" : text.trim().replace(START_STR, EMPTY).replace(END_STR, EMPTY); } return params; }
/** * 判断是不是迭代输出 * * @author JueYue * 2013-11-18 * @return * @throws Exception */ 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; }
/** * 判断是不是迭代输出 * * @Author JueYue * @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; }
/** * 解析参数行,获取参数列表 * * @author JueYue * 2013-11-18 * @param currentRow * @return */ private static String[] parseCurrentRowGetParams(XWPFTableRow currentRow) { List<XWPFTableCell> cells = currentRow.getTableCells(); String[] params = new String[cells.size()]; String text; for (int i = 0; i < cells.size(); i++) { text = cells.get(i).getText(); params[i] = text == null ? "" : text.trim().replace(START_STR, EMPTY).replace(END_STR, EMPTY); } return params; }
/** * Get the text - if any - encapsulated by this bookmark. The creator of a * Word document can chose to select one or more items of text and then * insert a bookmark at that location. The highlighted text will appear * between the square brackets that denote the location of a bookmark in the * document's text and they will be returned by a call to this method. * * @return An instance of the String class encapsulating any text that * appeared between the opening and closing square bracket associated with * this bookmark. * @throws XmlException Thrown if a problem is encountered parsing the XML * markup recovered from the document in order to construct a CTText * instance which may required to obtain the bookmarks text. */ public String getBookmarkText() throws XmlException { StringBuilder builder = null; // Are we dealing with a bookmarked table cell? If so, the entire // contents of the cell - if anything - must be recovered and returned. if(this._tableCell != null) { builder = new StringBuilder(this._tableCell.getText()); } else { builder = this.getTextFromBookmark(); } return(builder == null ? null : builder.toString()); }
/** * 获取表头数据 * * @param table * @param index * @return */ private Map<String, Integer> getTitleMap(XWPFTable table, int index, int headRows) { if (index < headRows) { throw new WordExportException(WordExportEnum.EXCEL_NO_HEAD); } Map<String, Integer> map = new HashMap<String, Integer>(); String text; for (int j = 0; j < headRows; j++) { List<XWPFTableCell> cells = table.getRow(index - j - 1).getTableCells(); for (int i = 0; i < cells.size(); i++) { text = cells.get(i).getText(); if (StringUtils.isEmpty(text)) { throw new WordExportException(WordExportEnum.EXCEL_HEAD_HAVA_NULL); } map.put(text, i); } } return map; }
/** * 获取表头数据 * * @param table * @param index * @return */ private Map<String, Integer> getTitleMap(XWPFTable table, int index, int headRows) { if (index < headRows) { throw new WordExportException(WordExportEnum.EXCEL_NO_HEAD); } Map<String, Integer> map = new HashMap<String, Integer>(); String text; for (int j = 0; j < headRows; j++) { List<XWPFTableCell> cells = table.getRow(index - j - 1).getTableCells(); for (int i = 0; i < cells.size(); i++) { text = cells.get(i).getText(); if (StringUtils.isEmpty(text)) { throw new WordExportException(WordExportEnum.EXCEL_HEAD_HAVA_NULL); } map.put(text, i); } } return map; }
/** * 获取表头数据 * * @param table * @param index * @return */ private Map<String, Integer> getTitleMap(XWPFTable table, int index, int headRows) { if (index < headRows) { throw new WordExportException(WordExportEnum.EXCEL_NO_HEAD); } Map<String, Integer> map = new HashMap<String, Integer>(); String text; for (int j = 0; j < headRows; j++) { List<XWPFTableCell> cells = table.getRow(index - j - 1).getTableCells(); for (int i = 0; i < cells.size(); i++) { text = cells.get(i).getText(); if (StringUtils.isEmpty(text)) { throw new WordExportException(WordExportEnum.EXCEL_HEAD_HAVA_NULL); } map.put(text, i); } } return map; }
/** * 获取表头数据 * * @param table * @param index * @return */ private Map<String, Integer> getTitleMap(XWPFTable table, int index, int headRows) { if (index < headRows) { throw new WordExportException(WordExportEnum.EXCEL_NO_HEAD); } Map<String, Integer> map = new HashMap<String, Integer>(); String text; for (int j = 0; j < headRows; j++) { List<XWPFTableCell> cells = table.getRow(index - j - 1).getTableCells(); for (int i = 0; i < cells.size(); i++) { text = cells.get(i).getText(); if (StringUtils.isEmpty(text)) { throw new WordExportException(WordExportEnum.EXCEL_HEAD_HAVA_NULL); } map.put(text, i); } } return map; }
/** * 获取表格第一行第一列单元格的值 * * @param table * @return */ private String getFirstCellValue(XWPFTable table){ String textValue = null; if(table==null||table.getRows().size()<1)return textValue; XWPFTableRow row = table.getRow(0); if(row==null||row.getTableCells().size()<1)return textValue; XWPFTableCell cell = row.getCell(0); textValue = cell.getText(); return textValue; }
/** * 获取表格第一行第一列单元格的值 * * @param table * @return */ private String getFirstCellValue(XWPFTable table) { String textValue = null; if (table == null || table.getRows().size() < 1) return textValue; XWPFTableRow row = table.getRow(0); if (row == null || row.getTableCells().size() < 1) return textValue; XWPFTableCell cell = row.getCell(0); textValue = cell.getText(); return textValue; }
/** * 获取表格第一行第一列单元格的值 * * @param table * @return */ private String getFirstCellValue(XWPFTable table) { String textValue = null; if (table == null || table.getRows().size() < 1) return textValue; XWPFTableRow row = table.getRow(0); if (row == null || row.getTableCells().size() < 1) return textValue; XWPFTableCell cell = row.getCell(0); textValue = cell.getText(); return textValue; }
for (XWPFTableCell cell : cells) { String cellTextString = cell.getText(); if (cellTextString != null && cellTextString.contains(placeholder)) { cellTextString = cellTextString.replace(placeholder,waterMarkText); cell.removeParagraph(0); XWPFParagraph addParagraph = cell.addParagraph(); XWPFRun run = addParagraph.createRun(); run.setFontFamily("Calibri"); run.setFontSize(10); run.setText(cellTextString); } }
XWPFDocument doc = new XWPFDocument(new FileInputStream(fileName)); List<XWPFTable> table = doc.getTables(); for (XWPFTable xwpfTable : table) { List<XWPFTableRow> row = xwpfTable.getRows(); for (XWPFTableRow xwpfTableRow : row) { List<XWPFTableCell> cell = xwpfTableRow.getTableCells(); for (XWPFTableCell xwpfTableCell : cell) { if (xwpfTableCell != null) { System.out.println(xwpfTableCell.getText()); String s = xwpfTableCell.getText(); for (XWPFParagraph p : xwpfTableCell.getParagraphs()) { for (XWPFRun run : p.getRuns()) { for (XWPFPicture pic : run.getEmbeddedPictures()) { byte[] pictureData = pic.getPictureData().getData(); System.out.println("picture : " + pictureData); } } } } } } }
XWPFDocument doc = new XWPFDocument(new FileInputStream(fileName)); List<XWPFTable> table = doc.getTables(); for (XWPFTable xwpfTable : table) { List<XWPFTableRow> row = xwpfTable.getRows(); for (XWPFTableRow xwpfTableRow : row) { List<XWPFTableCell> cell = xwpfTableRow.getTableCells(); for (XWPFTableCell xwpfTableCell : cell) { if (xwpfTableCell != null) { System.out.println(xwpfTableCell.getText()); String s = xwpfTableCell.getText(); for (XWPFParagraph p : xwpfTableCell.getParagraphs()) { for (XWPFRun run : p.getRuns()) { for (XWPFPicture pic : run.getEmbeddedPictures()) { byte[] pictureData = pic.getPictureData().getData(); System.out.println("picture : " + pictureData); } } } } } } }
private XWPFTable generatePosTableRows(final XWPFDocument templateDocument, final List<RechnungsPositionDO> positionen) { XWPFTable posTbl = null; for (XWPFTable tbl : templateDocument.getTables()) { if (tbl.getRow(0).getCell(0).getText().contains("Beschreibung")) { posTbl = tbl; } } for (int i = 2; i <= positionen.size(); i++) { copyTableRow(posTbl, i); } int rowCount = 1; for (RechnungsPositionDO position : positionen) { for (XWPFTableCell cell : posTbl.getRow(rowCount).getTableCells()) { for (XWPFParagraph cellParagraph : cell.getParagraphs()) { replaceInParagraph(cellParagraph, "id", String.valueOf(position.getNumber())); } } rowCount++; } return posTbl; }