List of usage examples for org.apache.poi.ss.usermodel Comment getString
public RichTextString getString();
From source file:org.specrunner.source.excel.SourceFactoryExcel.java
License:Open Source License
/** * Add information from cell comments.//from w w w. j av a 2s. com * * @param table * The table element. * @param caption * The table caption. * @param row * The row element. * @param item * The header element. * @param cell * The cell to read comments from. * @param p * The pair, if exist. */ private void addAttributes(Element table, Element caption, Element row, Element item, Cell cell, Dimension p) { Comment c = cell.getCellComment(); if (c != null) { RichTextString rts = c.getString(); if (rts != null) { String text = rts.getString(); StringTokenizer st = new StringTokenizer(text, "\n"); while (st.hasMoreTokens()) { String token = st.nextToken(); int pos = token.indexOf('='); if (pos > 0) { String name = token.substring(0, pos); String value = token.substring(pos + 1).replace("\"", ""); if (name.startsWith(TABLE_ATTRIBUTE)) { table.addAttribute( new Attribute(name.substring(TABLE_ATTRIBUTE.length(), name.length()), value)); } else if (name.startsWith(CAPTION_ATTRIBUTE)) { caption.addAttribute(new Attribute( name.substring(CAPTION_ATTRIBUTE.length(), name.length()), value)); } else if (name.startsWith(ROW_ATTRIBUTE)) { row.addAttribute( new Attribute(name.substring(ROW_ATTRIBUTE.length(), name.length()), value)); } else { item.addAttribute(new Attribute(name, value)); } } } } } if (p != null) { if (p.rows > 1) { item.addAttribute(new Attribute("rowspan", String.valueOf(p.rows))); } if (p.cols > 1) { item.addAttribute(new Attribute("colspan", String.valueOf(p.cols))); } } }
From source file:org.tiefaces.components.websheet.configuration.ConfigurationHandler.java
License:MIT License
/** * build command list from comment./*from w ww . j ava 2 s . c o m*/ * * @param sheet * sheet. * @param sheetRightCol * sheet right column. * @param cell * the cell * @param cList * command list. * @param cellAttributesMap * the cell attributes map * @return command list. */ private List<ConfigCommand> buildCommandList(final Sheet sheet, final int sheetRightCol, final Cell cell, final List<ConfigCommand> cList, final CellAttributesMap cellAttributesMap) { Comment comment = cell.getCellComment(); String text = comment.getString().getString(); String[] commentLines = text.split("\\n"); StringBuilder newComment = new StringBuilder(); boolean changed = false; for (String commentLine : commentLines) { String line = commentLine.trim(); if (ParserUtility.isCommandString(line)) { processCommandLine(sheet, cell, line, cList, sheetRightCol); changed = true; } else if (ParserUtility.isEmptyMethodString(line) || ParserUtility.isMethodString(line)) { processMethodLine(cell, line, cellAttributesMap); changed = true; } else { if (newComment.length() > 0) { newComment.append("\\n" + commentLine); } else { newComment.append(commentLine); } } } if (!changed) { moveCommentToMap(cell, text, cellAttributesMap.getTemplateCommentMap(), true); } else { // reset comment string if changed if (newComment.length() > 0) { moveCommentToMap(cell, newComment.toString(), cellAttributesMap.getTemplateCommentMap(), true); CreationHelper factory = sheet.getWorkbook().getCreationHelper(); RichTextString str = factory.createRichTextString(newComment.toString()); comment.setString(str); } else { // remove cell comment if new comment become empty. cell.removeCellComment(); } } return cList; }
From source file:org.tiefaces.components.websheet.utility.CellUtility.java
License:MIT License
/** * Creates the or insert comment.//from w w w .j a v a2 s. co m * * @param cell the cell * @param commentStr the comment str */ public static void createOrInsertComment(final Cell cell, final String commentStr) { XSSFSheet sheet = (XSSFSheet) cell.getSheet(); CreationHelper factory = sheet.getWorkbook().getCreationHelper(); Drawing drawing = sheet.createDrawingPatriarch(); Comment comment = cell.getCellComment(); String originStr = ""; if (comment == null) { // Below code are from POI busy manual. // When the comment box is visible, have it show in a 1x3 space ClientAnchor anchor = createCommentAnchor(cell, factory); // Create the comment and set the text+author comment = drawing.createCellComment(anchor); } else { originStr = comment.getString().getString() + "\n"; } originStr += commentStr; RichTextString str = factory.createRichTextString(originStr); comment.setString(str); comment.setAuthor(""); // Assign the comment to the cell cell.setCellComment(comment); comment.setColumn(cell.getColumnIndex()); comment.setRow(cell.getRowIndex()); }
From source file:org.wandora.application.tools.extractors.excel.AbstractExcelExtractor.java
License:Open Source License
public Topic getCommentTopic(Cell cell, TopicMap tm) throws TopicMapException { Comment comment = cell.getCellComment(); if (comment != null) { RichTextString rts = comment.getString(); String str = rts.getString(); String basename = str.replace('\n', ' '); basename = basename.replace('\r', ' '); basename = basename.replace('\t', ' '); Topic topic = getOrCreateTopic(tm, EXCEL_COMMENT_SI_PREFIX + "/" + urlEncode(basename), basename); topic.setData(getCommentTypeTopic(tm), tm.getTopic(XTMPSI.getLang(DEFAULT_LANG)), str); topic.addType(getCommentTypeTopic(tm)); return topic; }/*from www.ja v a 2s.c o m*/ return null; }