/** * XLSX document does not store empty cells and it might be an issue for formula calculations and etc. * So we need to create fake template cell for each empty cell. */ protected void createFakeTemplateCellsForEmptyOnes(Range oneRowRange, Map<CellReference, Cell> cellsForOneRowRange, List<Cell> templateCells) { if (oneRowRange.toCellReferences().size() != templateCells.size()) { final HashBiMap<CellReference, Cell> referencesToCells = HashBiMap.create(cellsForOneRowRange); for (CellReference cellReference : oneRowRange.toCellReferences()) { if (!cellsForOneRowRange.containsKey(cellReference)) { Cell newCell = Context.getsmlObjectFactory().createCell(); newCell.setV(null); newCell.setT(STCellType.STR); newCell.setR(cellReference.toReference()); templateCells.add(newCell); referencesToCells.put(cellReference, newCell); } } templateCells.sort((o1, o2) -> { CellReference cellReference1 = referencesToCells.inverse().get(o1); CellReference cellReference2 = referencesToCells.inverse().get(o2); return cellReference1.compareTo(cellReference2); }); } }
/** * XLSX document does not store empty cells and it might be an issue for formula calculations and etc. * So we need to create fake template cell for each empty cell. */ protected void createFakeTemplateCellsForEmptyOnes(Range oneRowRange, Map<CellReference, Cell> cellsForOneRowRange, List<Cell> templateCells) { if (oneRowRange.toCellReferences().size() != templateCells.size()) { final HashBiMap<CellReference, Cell> referencesToCells = HashBiMap.create(cellsForOneRowRange); for (CellReference cellReference : oneRowRange.toCellReferences()) { if (!cellsForOneRowRange.containsKey(cellReference)) { Cell newCell = Context.getsmlObjectFactory().createCell(); newCell.setV(null); newCell.setT(STCellType.STR); newCell.setR(cellReference.toReference()); templateCells.add(newCell); referencesToCells.put(cellReference, newCell); } } Collections.sort(templateCells, new Comparator<Cell>() { @Override public int compare(Cell o1, Cell o2) { CellReference cellReference1 = referencesToCells.inverse().get(o1); CellReference cellReference2 = referencesToCells.inverse().get(o2); return cellReference1.compareTo(cellReference2); } }); } }
public Cell createCell(org.xlsx4j.sml.ObjectFactory factory, String stringContent, int colNum, long rowNum) { Cell cell = factory.createCell(); cell.setT(STCellType.STR); cell.setV(stringContent); cell.setR(CellReference.convertNumToColString(colNum - 1) + "" + rowNum); cell.setS(0L); return cell; }
newCell.setR(newRef.toReference());
newCell.setR(newRef.toReference());