List of usage examples for org.apache.poi.ss.usermodel Cell getSheet
Sheet getSheet();
From source file:org.tiefaces.components.websheet.utility.CellUtility.java
License:MIT License
/** * clone existing comments into new cell comment. * /* ww w. j av a 2s. co m*/ * @param sourceCell * source cell. * @param newCell * target cell. */ public static void cloneComment(final Cell sourceCell, final Cell newCell) { XSSFSheet sheet = (XSSFSheet) newCell.getSheet(); CreationHelper factory = sheet.getWorkbook().getCreationHelper(); Drawing drawing = sheet.createDrawingPatriarch(); XSSFComment sourceComment = (XSSFComment) sourceCell.getCellComment(); // Below code are from POI busy manual. // When the comment box is visible, have it show in a 1x3 space ClientAnchor anchor = createCommentAnchor(newCell, factory); // Create the comment and set the text+author Comment comment = drawing.createCellComment(anchor); RichTextString str = factory.createRichTextString(sourceComment.getString().toString()); comment.setString(str); comment.setAuthor(sourceComment.getAuthor()); // Assign the comment to the cell newCell.setCellComment(comment); comment.setColumn(newCell.getColumnIndex()); comment.setRow(newCell.getRowIndex()); // As POI doesn't has well support for comments, // So we have to use low level api to match the comments. matchCommentSettings(newCell, sourceCell); }
From source file:org.tiefaces.components.websheet.utility.CellUtility.java
License:MIT License
/** * Creates the or insert comment./* w ww . jav a2 s.c o 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.tiefaces.components.websheet.utility.CellUtility.java
License:MIT License
/** * Find vmldrawing part according to cell. * // ww w. j a v a2 s . c om * @param cell * cell. * @return vmldrawing. */ private static XSSFVMLDrawing getVmlDrawingFromCell(final Cell cell) { XSSFSheet sourceSheet = (XSSFSheet) cell.getSheet(); for (POIXMLDocumentPart sourcePart : sourceSheet.getRelations()) { if ((sourcePart != null) && (sourcePart instanceof XSSFVMLDrawing)) { return (XSSFVMLDrawing) sourcePart; } } return null; }
From source file:org.tiefaces.components.websheet.utility.CellUtility.java
License:MIT License
/** * Gets the skey from poi cell./* w w w . j a v a 2 s .c o m*/ * * @param poiCell the poi cell * @return the skey from poi cell */ public static String getSkeyFromPoiCell(final Cell poiCell) { return poiCell.getSheet().getSheetName() + "!" + CellUtility.getCellIndexNumberKey(poiCell.getColumnIndex(), poiCell.getRowIndex()); }
From source file:org.tiefaces.components.websheet.utility.ParserUtility.java
License:MIT License
/** * get attribute key in map by cell./*w ww.j a v a 2s . c o m*/ * * @param cell * input cell. * @return key. */ public static String getAttributeKeyInMapByCell(final Cell cell) { if (cell == null) { return null; } // map's key is sheetName!$columnIndex$rowIndex return cell.getSheet().getSheetName() + "!" + CellUtility.getCellIndexNumberKey(cell); }
From source file:org.tiefaces.components.websheet.utility.SaveAttrsUtility.java
License:MIT License
/** * Parses the save attr./*from w w w .ja v a 2 s . c om*/ * * @param cell * the cell * @param saveCommentsMap * the save comments map * @return the string */ public static String parseSaveAttr(final Cell cell, final Map<String, String> saveCommentsMap) { if (cell != null) { String key = cell.getSheet().getSheetName() + "!" + CellUtility.getCellIndexNumberKey(cell.getColumnIndex(), cell.getRowIndex()); String saveAttr = null; if (saveCommentsMap != null) { saveAttr = ParserUtility.getStringBetweenBracket(saveCommentsMap.get(key)); } if ((saveAttr == null) && (cell.getCellTypeEnum() == CellType.STRING)) { saveAttr = SaveAttrsUtility.parseSaveAttrString(cell.getStringCellValue()); } if ((saveAttr != null) && (!saveAttr.isEmpty())) { return TieConstants.CELL_ADDR_PRE_FIX + cell.getColumnIndex() + "=" + saveAttr + ","; } } return ""; }
From source file:org.wandora.application.tools.extractors.excel.AbstractExcelExtractor.java
License:Open Source License
public void associateToSheet(Cell cell, TopicMap tm) throws TopicMapException { if (cell.getSheet() != null) { Topic sheetTypeTopic = getSheetTypeTopic(tm); Topic sheetTopic = getSheetTopic(cell, tm); Topic cellTypeTopic = getCellTypeTopic(tm); Topic cellTopic = getCellTopic(cell, tm); if (sheetTypeTopic != null && sheetTopic != null && cellTypeTopic != null && cellTopic != null) { Association a = tm.createAssociation(sheetTypeTopic); a.addPlayer(cellTopic, cellTypeTopic); a.addPlayer(sheetTopic, sheetTypeTopic); }// w ww. ja va2 s .c o m } }
From source file:org.wandora.application.tools.extractors.excel.AbstractExcelExtractor.java
License:Open Source License
public Topic getCellTopic(Cell cell, TopicMap tm) throws TopicMapException { String cellIdentifier = null; switch (CELL_TOPIC_IS_BASED_ON) { case CELL_VALUE: { cellIdentifier = getCellValueAsString(cell); break;/*from www . j av a 2 s . co m*/ } case CELL_SHEET_AND_LOCATION: { Sheet sheet = cell.getSheet(); String sheetName = sheet.getSheetName(); cellIdentifier = sheetName + "-" + cell.getColumnIndex() + "-" + cell.getRowIndex(); break; } case CELL_LOCATION: { cellIdentifier = cell.getColumnIndex() + "-" + cell.getRowIndex(); break; } case CELL_HASH: { cellIdentifier = Integer.toString(cell.hashCode()); break; } } if (cellIdentifier != null) { String si = EXCEL_CELL_SI_PREFIX + "/" + urlEncode(cellIdentifier); Topic cellTopic = getOrCreateTopic(tm, si, cellIdentifier); cellTopic.addType(getCellTypeTopic(tm)); return cellTopic; } return null; }
From source file:org.wandora.application.tools.extractors.excel.AbstractExcelExtractor.java
License:Open Source License
public Topic getSheetTopic(Cell cell, TopicMap tm) throws TopicMapException { Sheet sheet = cell.getSheet(); if (sheet != null) { String sheetName = sheet.getSheetName(); Topic topic = getOrCreateTopic(tm, EXCEL_SHEET_SI_PREFIX + "/" + urlEncode(sheetName), sheetName); topic.addType(getSheetTypeTopic(tm)); return topic; }//from w w w .j a v a 2s . c om return null; }
From source file:ru.icc.cells.ssdc.DataLoader.java
License:Apache License
private void fillCell(CCell cell, Cell excelCell) { String rawTextualContent = null; CellType cellType = null;/* ww w .j av a 2 s .co m*/ String text = null; if (withoutSuperscript) { if (hasSuperscriptText(excelCell)) { text = getNotSuperscriptText(excelCell); } else { text = getText(excelCell); } } else { text = getText(excelCell); } cell.setText(text); rawTextualContent = getFormatCellValue(excelCell); cell.setRawText(rawTextualContent); switch (excelCell.getCellType()) { case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(excelCell)) { //rawTextualContent = "DATE"; // TODO - ? cellType = CellType.DATE; } else { cellType = CellType.NUMERIC; } break; case Cell.CELL_TYPE_STRING: cellType = CellType.STRING; break; case Cell.CELL_TYPE_BOOLEAN: cellType = CellType.BOOLEAN; break; case Cell.CELL_TYPE_FORMULA: cellType = CellType.FORMULA; break; case Cell.CELL_TYPE_BLANK: cellType = CellType.BLANK; break; case Cell.CELL_TYPE_ERROR: cellType = CellType.ERROR; break; } cell.setId(this.cellCount); cell.setCellType(cellType); int height = excelCell.getRow().getHeight(); cell.setHeight(height); int width = excelCell.getSheet().getColumnWidth(excelCell.getColumnIndex()); cell.setWidth(width); CellStyle excelCellStyle = excelCell.getCellStyle(); CStyle cellStyle = cell.getStyle(); fillCellStyle(cellStyle, excelCellStyle); String reference = new CellReference(excelCell).formatAsString(); cell.setProvenance(reference); this.cellCount++; }