@Override public int getColumnIndex() { return _cell.getColumnIndex(); } @Override
/* package */ boolean isCellInArrayFormulaContext(XSSFCell cell) { for (CellRangeAddress range : arrayFormulas) { if (range.isInRange(cell.getRowIndex(), cell.getColumnIndex())) { return true; } } return false; }
/** * Assign a comment to this cell. If the supplied comment is null, * the comment for this cell will be removed. * * @param comment the XSSFComment associated with this cell */ @Override public void setCellComment(Comment comment) { if(comment == null) { removeCellComment(); return; } comment.setAddress(getRowIndex(), getColumnIndex()); }
void nextMeetingAssignmentListCell(List<MeetingAssignment> meetingAssignmentList, Function<MeetingAssignment, String> stringFunction, List<String> filteredConstraintNames) { if (meetingAssignmentList == null) { meetingAssignmentList = Collections.emptyList(); } HardMediumSoftScore score = meetingAssignmentList.stream() .map(indictmentMap::get).filter(Objects::nonNull) .flatMap(indictment -> indictment.getConstraintMatchSet().stream()) // Filter out filtered constraints .filter(constraintMatch -> filteredConstraintNames == null || filteredConstraintNames.contains(constraintMatch.getConstraintName())) .map(constraintMatch -> (HardMediumSoftScore) constraintMatch.getScore()) // Filter out positive constraints .filter(indictmentScore -> !(indictmentScore.getHardScore() >= 0 && indictmentScore.getSoftScore() >= 0)) .reduce(Score::add).orElse(HardMediumSoftScore.ZERO); XSSFCell cell = getXSSFCellOfScore(score); if (!meetingAssignmentList.isEmpty()) { ClientAnchor anchor = creationHelper.createClientAnchor(); anchor.setCol1(cell.getColumnIndex()); anchor.setCol2(cell.getColumnIndex() + 4); anchor.setRow1(currentRow.getRowNum()); anchor.setRow2(currentRow.getRowNum() + 4); Comment comment = currentDrawing.createCellComment(anchor); String commentString = getMeetingAssignmentListString(meetingAssignmentList); comment.setString(creationHelper.createRichTextString(commentString)); cell.setCellComment(comment); } cell.setCellValue(meetingAssignmentList.stream().map(stringFunction).collect(joining("\n"))); currentRow.setHeightInPoints(Math.max(currentRow.getHeightInPoints(), meetingAssignmentList.size() * currentSheet.getDefaultRowHeightInPoints())); }
anchor.setCol1(cell.getColumnIndex()); anchor.setCol2(cell.getColumnIndex() + 4); anchor.setRow1(currentRow.getRowNum()); anchor.setRow2(currentRow.getRowNum() + 4);
/** * Construct a XSSFRow. * * @param row the xml bean containing all cell definitions for this row. * @param sheet the parent sheet. */ protected XSSFRow(CTRow row, XSSFSheet sheet) { _row = row; _sheet = sheet; _cells = new TreeMap<>(); for (CTCell c : row.getCArray()) { XSSFCell cell = new XSSFCell(this, c); // Performance optimization for bug 57840: explicit boxing is slightly faster than auto-unboxing, though may use more memory final Integer colI = Integer.valueOf(cell.getColumnIndex()); // NOSONAR _cells.put(colI, cell); sheet.onReadCell(cell); } if (! row.isSetR()) { // Certain file format writers skip the row number // Assume no gaps, and give this the next row number int nextRowNum = sheet.getLastRowNum()+2; if (nextRowNum == 2 && sheet.getPhysicalNumberOfRows() == 0) { nextRowNum = 1; } row.setR(nextRowNum); } }
/** * Sets column index of this cell * * @param num column index of this cell */ protected void setCellNum(int num) { checkBounds(num); _cellNum = num; String ref = new CellReference(getRowIndex(), getColumnIndex()).formatAsString(); _cell.setR(ref); }
/* package */ XSSFCell getFirstCellInArrayFormula(XSSFCell cell) { for (CellRangeAddress range : arrayFormulas) { if (range.isInRange(cell.getRowIndex(), cell.getColumnIndex())) { return getRow(range.getFirstRow()).getCell(range.getFirstColumn()); } } return null; }
/** * Removes the comment for this cell, if there is one. */ @Override public void removeCellComment() { XSSFComment comment = getCellComment(); if(comment != null){ CellAddress ref = new CellAddress(getReference()); XSSFSheet sh = getSheet(); sh.getCommentsTable(false).removeComment(ref); sh.getVMLDrawing(false).removeCommentShape(getRowIndex(), getColumnIndex()); } }
logger.log(POILogger.DEBUG, "Extracting with xpath " + xpathString + " : value is '" + textContent + "'"); XSSFCell cell = singleXmlCell.getReferencedCell(); logger.log(POILogger.DEBUG, "Setting '" + textContent + "' to cell " + cell.getColumnIndex() + "-" + cell.getRowIndex() + " in sheet " + cell.getSheet().getSheetName()); setCellValue(textContent, cell, xmlDataType); cell = row.createCell(columnId); logger.log(POILogger.DEBUG, "Setting '" + value + "' to cell " + cell.getColumnIndex() + "-" + cell.getRowIndex() + " in sheet " + table.getXSSFSheet().getSheetName()); setCellValue(value, cell, xmlColumnPr.getXmlDataType());
public void updateCellReferencesForShifting(String msg){ if(isPartOfArrayFormulaGroup()) notifyArrayFormulaChanging(msg); CalculationChain calcChain = getSheet().getWorkbook().getCalculationChain(); int sheetId = (int)getSheet().sheet.getSheetId(); //remove the reference in the calculation chain if(calcChain != null) calcChain.removeItem(sheetId, getReference()); CTCell ctCell = getCTCell(); String r = new CellReference(getRowIndex(), getColumnIndex()).formatAsString(); ctCell.setR(r); }
/** * Creates a non shared formula from the shared formula counterpart * * @param si Shared Group Index * @return non shared formula created for the given shared formula and this cell */ private String convertSharedFormula(int si, BaseXSSFEvaluationWorkbook fpb){ XSSFSheet sheet = getSheet(); CTCellFormula f = sheet.getSharedFormula(si); if(f == null) { throw new IllegalStateException( "Master cell of a shared formula with sid="+si+" was not found"); } String sharedFormula = f.getStringValue(); //Range of cells which the shared formula applies to String sharedFormulaRange = f.getRef(); CellRangeAddress ref = CellRangeAddress.valueOf(sharedFormulaRange); int sheetIndex = sheet.getWorkbook().getSheetIndex(sheet); SharedFormula sf = new SharedFormula(SpreadsheetVersion.EXCEL2007); Ptg[] ptgs = FormulaParser.parse(sharedFormula, fpb, FormulaType.CELL, sheetIndex, getRowIndex()); Ptg[] fmla = sf.convertSharedFormulas(ptgs, getRowIndex() - ref.getFirstRow(), getColumnIndex() - ref.getFirstColumn()); return FormulaRenderer.toFormulaString(fpb, fmla); }
/** * when a cell with a 'master' shared formula is removed, the next cell in the range becomes the master * @param cell The cell that is removed * @param evalWb BaseXSSFEvaluationWorkbook in use, if one exists */ protected void onDeleteFormula(XSSFCell cell, BaseXSSFEvaluationWorkbook evalWb){ CTCellFormula f = cell.getCTCell().getF(); if (f != null && f.getT() == STCellFormulaType.SHARED && f.isSetRef() && f.getStringValue() != null) { CellRangeAddress ref = CellRangeAddress.valueOf(f.getRef()); if(ref.getNumberOfCells() > 1){ DONE: for(int i = cell.getRowIndex(); i <= ref.getLastRow(); i++){ XSSFRow row = getRow(i); if(row != null) for(int j = cell.getColumnIndex(); j <= ref.getLastColumn(); j++){ XSSFCell nextCell = row.getCell(j); if(nextCell != null && nextCell != cell && nextCell.getCellType() == CellType.FORMULA){ CTCellFormula nextF = nextCell.getCTCell().getF(); nextF.setStringValue(nextCell.getCellFormula(evalWb)); CellRangeAddress nextRef = new CellRangeAddress( nextCell.getRowIndex(), ref.getLastRow(), nextCell.getColumnIndex(), ref.getLastColumn()); nextF.setRef(nextRef.formatAsString()); sharedFormulas.put((int)nextF.getSi(), nextF); break DONE; } } } } } }
/** * Construct a XSSFCell. * * @param row the parent row. * @param cell the xml bean containing information about the cell. */ protected XSSFCell(XSSFRow row, CTCell cell) { _cell = cell; _row = row; if (cell.getR() != null) { _cellNum = new CellReference(cell.getR()).getCol(); } else { int prevNum = row.getLastCellNum(); if(prevNum != -1){ _cellNum = row.getCell(prevNum-1, MissingCellPolicy.RETURN_NULL_AND_BLANK).getColumnIndex() + 1; } } _sharedStringSource = row.getSheet().getWorkbook().getSharedStringSource(); _stylesSource = row.getSheet().getWorkbook().getStylesSource(); }
for (final Cell c : srcRow){ final XSSFCell srcCell = (XSSFCell)c; final XSSFCell destCell = createCell(srcCell.getColumnIndex(), srcCell.getCellType()); destCell.copyCellFrom(srcCell, policy);
/** * Returns cell comment associated with this cell * * @return the cell comment associated with this cell or <code>null</code> */ public XSSFComment getCellComment() { return getSheet().getCellComment(_row.getRowNum(), getColumnIndex()); }
private boolean isMergedCell(PdfCellNode cell) { for (MergedRegion region : getMergedRegions()) { if (region.isInRegion(cell.getCell().getRowIndex(), cell.getCell().getColumnIndex())) { return true; } } return false; }
/* package */ XSSFCell getFirstCellInArrayFormula(XSSFCell cell) { for (CellRangeAddress range : arrayFormulas) { if (range.isInRange(cell.getRowIndex(), cell.getColumnIndex())) { return getRow(range.getFirstRow()).getCell(range.getFirstColumn()); } } return null; }
/** * Removes the comment for this cell, if there is one. */ public void removeCellComment() { XSSFComment comment = getCellComment(); if(comment != null){ String ref = _cell.getR(); XSSFSheet sh = getSheet(); sh.getCommentsTable(false).removeComment(ref); sh.getVMLDrawing(false).removeCommentShape(getRowIndex(), getColumnIndex()); } }
public void updateCellReferencesForShifting(String msg){ if(isPartOfArrayFormulaGroup()) notifyArrayFormulaChanging(msg); CalculationChain calcChain = getSheet().getWorkbook().getCalculationChain(); int sheetId = (int)getSheet().sheet.getSheetId(); //remove the reference in the calculation chain if(calcChain != null) calcChain.removeItem(sheetId, getReference()); CTCell ctCell = getCTCell(); String r = new CellReference(getRowIndex(), getColumnIndex()).formatAsString(); ctCell.setR(r); }