public CellReference(String sheet, Cell cell) { this(sheet, cell.getR()); }
public CellReference(String sheet, Cell cell) { this(sheet, cell.getR()); }
... for (Cell c : r.getC() ) { if (c.getT().equals(STCellType.S)) { System.out.println( " " + c.getR() + " contains " + sharedStrings.getJaxbElement().getSi().get(Integer.parseInt(c.getV())).getT() ); } else { // TODO: handle other cell types System.out.println( " " + c.getR() + " contains " + c.getV() ); } } ...
protected void updateRangeMappings(BandData band, Range templateRange, List<Cell> resultCells) { if (resultCells != null && !resultCells.isEmpty()) { Range resultRange = Range.fromCells(templateRange.getSheet(), getFirst(resultCells).getR(), resultCells.get(resultCells.size() - 1).getR()); rangeDependencies.addDependency(templateRange, resultRange); bandsForRanges.add(band, templateRange, resultRange); lastRenderedRangeForBandName.put(band.getName(), resultRange); } }
protected void updateRangeMappings(BandData band, Range templateRange, List<Cell> resultCells) { if (resultCells != null && !resultCells.isEmpty()) { Range resultRange = Range.fromCells(templateRange.getSheet(), getFirst(resultCells).getR(), resultCells.get(resultCells.size() - 1).getR()); rangeDependencies.addDependency(templateRange, resultRange); bandsForRanges.add(band, templateRange, resultRange); lastRenderedRangeForBandName.put(band.getName(), resultRange); } }
public Map<CellReference, Cell> getCellsByRange(Range range) { Worksheet sheet = getSheetByName(range.getSheet()); SheetData data = sheet.getSheetData(); Map<CellReference, Cell> result = new LinkedHashMap<CellReference, Cell>(); for (int i = 1; i <= data.getRow().size(); i++) { Row row = data.getRow().get(i - 1); if (range.getFirstRow() <= row.getR() && row.getR() <= range.getLastRow()) { List<Cell> c = row.getC(); for (Cell cell : c) { CellReference cellReference = new CellReference(range.getSheet(), cell.getR()); if (range.getFirstColumn() <= cellReference.getColumn() && cellReference.getColumn() <= range.getLastColumn()) { result.put(cellReference, cell); } } } } return result; }
public Map<CellReference, Cell> getCellsByRange(Range range) { Worksheet sheet = getSheetByName(range.getSheet()); SheetData data = sheet.getSheetData(); Map<CellReference, Cell> result = new LinkedHashMap<>(); for (int i = 1; i <= data.getRow().size(); i++) { Row row = data.getRow().get(i - 1); if (range.getFirstRow() <= row.getR() && row.getR() <= range.getLastRow()) { List<Cell> c = row.getC(); for (Cell cell : c) { CellReference cellReference = new CellReference(range.getSheet(), cell.getR()); if (range.getFirstColumn() <= cellReference.getColumn() && cellReference.getColumn() <= range.getLastColumn()) { result.put(cellReference, cell); } } } } return result; }
protected void updateFormula(Cell cellWithFormula, Range originalFormulaRange, Range formulaRange, CTCalcChain calculationChain, int formulaCount) { CTCellFormula formula = cellWithFormula.getF(); formula.setValue(formula.getValue().replace(originalFormulaRange.toRange(), formulaRange.toRange())); if (originalFormulaRange.isOneCellRange() && formulaRange.isOneCellRange()) { //here we check that there are no alpha-numeric symbols around the single reference String pattern = "(?<!\\w+)" + originalFormulaRange.toFirstCellReference() + "(?!\\w+)"; formula.setValue(formula.getValue().replaceAll(pattern, formulaRange.toFirstCellReference())); } if (calculationChain != null) { CTCalcCell calcCell = new CTCalcCell(); calcCell.setR(cellWithFormula.getR()); String sheetName = originalFormulaRange.getSheet(); Sheets sheets = template.getWorkbook().getSheets(); if (sheets != null && sheets.getSheet() != null) { for (Sheet sheet : sheets.getSheet()) { if (Objects.equals(sheet.getName(), sheetName)) { calcCell.setI((int) sheet.getSheetId()); break; } } } calculationChain.getC().add(calcCell); } }
Worksheet worksheet = getWorksheet(row); Set<Range> formulaRanges = Range.fromCellFormula(result.getSheetName(worksheet), cellWithFormula); CellReference formulaCellReference = new CellReference(result.getSheetName(worksheet), cellWithFormula.getR());
protected void updateFormula(Cell cellWithFormula, Range originalFormulaRange, Range formulaRange, CTCalcChain calculationChain, int formulaCount) { CTCellFormula formula = cellWithFormula.getF(); formula.setValue(formula.getValue().replace(originalFormulaRange.toRange(), formulaRange.toRange())); if (originalFormulaRange.isOneCellRange() && formulaRange.isOneCellRange()) { //here we check that there are no alpha-numeric symbols around the single reference String pattern = "(?<!\\w+)" + originalFormulaRange.toFirstCellReference() + "(?!\\w+)"; formula.setValue(formula.getValue().replaceAll(pattern, formulaRange.toFirstCellReference())); } if (calculationChain != null) { CTCalcCell calcCell = new CTCalcCell(); calcCell.setR(cellWithFormula.getR()); String sheetName = originalFormulaRange.getSheet(); Sheets sheets = template.getWorkbook().getSheets(); if (sheets != null && sheets.getSheet() != null) { for (Sheet sheet : sheets.getSheet()) { if (Objects.equals(sheet.getName(), sheetName)) { calcCell.setI((int) sheet.getSheetId()); break; } } } calculationChain.getC().add(calcCell); } }
Worksheet worksheet = getWorksheet(row); Set<Range> formulaRanges = Range.fromCellFormula(result.getSheetName(worksheet), cellWithFormula); CellReference formulaCellReference = new CellReference(result.getSheetName(worksheet), cellWithFormula.getR());
CellReference newRef = new CellReference(templateRange.getSheet(), newCell.getR()); newRef.move(newRow.getR().intValue(), newRef.getColumn());
CellReference newRef = new CellReference(templateRange.getSheet(), newCell.getR()); newRef.move(newRow.getR().intValue(), newRef.getColumn());
List<Range> resultRanges = rangeDependencies.resultsForTemplate(templateRange); CellReference cellReference = new CellReference(result.getSheetName(worksheet), cellWithFormula.getR()); for (Range resultRange : resultRanges) { if (resultRange.contains(cellReference)) {
List<Range> resultRanges = rangeDependencies.resultsForTemplate(templateRange); CellReference cellReference = new CellReference(result.getSheetName(worksheet), cellWithFormula.getR()); for (Range resultRange : resultRanges) { if (resultRange.contains(cellReference)) {
@Override public void inlineToXlsx(SpreadsheetMLPackage pkg, WorksheetPart worksheetPart, Cell newCell, Object paramValue, Matcher matcher) { try { Image image = new Image(paramValue, matcher); if (image.isValid()) { BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(pkg, worksheetPart, image.imageContent); CTOneCellAnchor anchor = new CTOneCellAnchor(); anchor.setFrom(new CTMarker()); CellReference cellReference = new CellReference("", newCell.getR()); anchor.getFrom().setCol(cellReference.getColumn() - 1); anchor.getFrom().setRow(cellReference.getRow() - 1); anchor.setExt(new CTPositiveSize2D()); anchor.getExt().setCx(XlsxUtils.convertPxToEmu(image.width)); anchor.getExt().setCy(XlsxUtils.convertPxToEmu(image.height)); newCell.setV(null); putImage(worksheetPart, pkg, imagePart, anchor); } } catch (Exception e) { throw new ReportFormattingException("An error occurred while inserting bitmap to xlsx file", e); } }
@Override public void inlineToXlsx(SpreadsheetMLPackage pkg, WorksheetPart worksheetPart, Cell newCell, Object paramValue, Matcher matcher) { try { Image image = new Image(paramValue, matcher); if (image.isValid()) { BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(pkg, worksheetPart, image.imageContent); CTOneCellAnchor anchor = new CTOneCellAnchor(); anchor.setFrom(new CTMarker()); CellReference cellReference = new CellReference("", newCell.getR()); anchor.getFrom().setCol(cellReference.getColumn() - 1); anchor.getFrom().setRow(cellReference.getRow() - 1); anchor.setExt(new CTPositiveSize2D()); anchor.getExt().setCx(XlsxUtils.convertPxToEmu(image.width)); anchor.getExt().setCy(XlsxUtils.convertPxToEmu(image.height)); newCell.setV(null); putImage(worksheetPart, pkg, imagePart, anchor); } } catch (Exception e) { throw new ReportFormattingException("An error occurred while inserting bitmap to xlsx file", e); } }