/** * Detect cell type based on the "t" attribute of the CTCell bean */ private static int getBaseCellType(Cell _cell, boolean blankCells) { switch (_cell.getT()) { case B: return CELL_TYPE_BOOLEAN; case N: if (_cell.getV()==null && blankCells) { // ooxml does have a separate cell type of 'blank'. A blank cell gets encoded as // (either not present or) a numeric cell with no value set. // The formula evaluator (and perhaps other clients of this interface) needs to // distinguish blank values which sometimes get translated into zero and sometimes // empty string, depending on context return CELL_TYPE_BLANK; } return CELL_TYPE_NUMERIC; case E: return CELL_TYPE_ERROR; case S: // String is in shared strings case INLINE_STR: // String is inline in cell case STR: return CELL_TYPE_STRING; default: throw new IllegalStateException("Illegal cell type: " + _cell.getT()); } }
/** * Detect cell type based on the "t" attribute of the CTCell bean */ private static int getBaseCellType(Cell _cell, boolean blankCells) { switch (_cell.getT()) { case B: return CELL_TYPE_BOOLEAN; case N: if (_cell.getV()==null && blankCells) { // ooxml does have a separate cell type of 'blank'. A blank cell gets encoded as // (either not present or) a numeric cell with no value set. // The formula evaluator (and perhaps other clients of this interface) needs to // distinguish blank values which sometimes get translated into zero and sometimes // empty string, depending on context return CELL_TYPE_BLANK; } return CELL_TYPE_NUMERIC; case E: return CELL_TYPE_ERROR; case S: // String is in shared strings case INLINE_STR: // String is inline in cell case STR: return CELL_TYPE_STRING; default: throw new IllegalStateException("Illegal cell type: " + _cell.getT()); } }
... 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() ); } } ...
public String getCellValue(Cell cell) { if (cell.getV() == null) return null; if (cell.getT().equals(STCellType.S)) { CTSst jaxbElement; try { jaxbElement = sharedStrings.getContents(); } catch (Docx4JException e) { throw new RuntimeException("Unable to get strings contents", e); } CTRst ctRst = jaxbElement.getSi().get(Integer.parseInt(cell.getV())); String value = null; if (ctRst.getT() != null) { value = ctRst.getT().getValue(); } else { if (ctRst.getR() != null) { StringBuilder stringBuilder = new StringBuilder(); for (CTRElt ctrElt : ctRst.getR()) { if (ctrElt.getT() != null) { stringBuilder.append(ctrElt.getT().getValue()); } } value = stringBuilder.toString(); } } return value; } else { return cell.getV(); } }
public String getCellValue(Cell cell) { if (cell.getV() == null) return null; if (cell.getT().equals(STCellType.S)) { CTRst ctRst = sharedStrings.getJaxbElement().getSi().get(Integer.parseInt(cell.getV())); String value = null; if (ctRst.getT() != null) { value = ctRst.getT().getValue(); } else { if (ctRst.getR() != null) { StringBuilder stringBuilder = new StringBuilder(); for (CTRElt ctrElt : ctRst.getR()) { if (ctrElt.getT() != null) { stringBuilder.append(ctrElt.getT().getValue()); } } value = stringBuilder.toString(); } } return value; } else { return cell.getV(); } }
newCell.setV(value); if (newCell.getT() == STCellType.S) { newCell.setT(STCellType.STR);
newCell.setV(value); if (newCell.getT() == STCellType.S) { newCell.setT(STCellType.STR);