public void readUnchangableCell(Row row, int cellIdx, FormDisplayCell tableCell, DataDto dto) { Cell cell = row.getCell(cellIdx); if (null == cell) { log.warn( "Table import. Table " + metaData.getTableName() + " Cell at row: " + (row.getRowNum() + 1) + " col: " + (cellIdx + 1) + " current value: " + dto.getValue() + " cell is null."); } if (cell.getCellType() != Cell.CELL_TYPE_NUMERIC && cell.getCellType() != Cell.CELL_TYPE_FORMULA) { log.warn( "Table import. Table " + metaData.getTableName() + " Cell at row: " + (row.getRowNum() + 1) + " col: " + (cellIdx + 1) + " current value: " + dto.getValue() + " cell is is not numeric."); } double editedValue = cell.getNumericCellValue(); if ("0.00%".equals(cell.getCellStyle().getDataFormatString())) { // Percent editedValue = editedValue * 100; } String editedValueString = formatter.formatValueToAtLeastDP(dto, editedValue); if (!editedValueString.equals(dto.getValue()) && !editedValueString.isEmpty()) { // value has changed so log a warning metaData.addWarning( row.getRowNum(), cellIdx, dto.getValue(), editedValueString, "This is a " + tableCell.getCellType().name() + " cell. It cannot be changed."); } }
public String readDataCell(Row row, int cellIdx, DataDto dto, CellType cellType) { Cell cell = row.getCell(cellIdx); if (null == cell) { log.warn( "Table import. Table " + metaData.getTableName() + " Cell at row: " + (row.getRowNum() + 1) + " col: " + (cellIdx + 1) + " current value: " + dto.getValue() + " cell is null."); return null; } String editedValueString = null; if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC || cell.getCellType() == Cell.CELL_TYPE_FORMULA) { try { double editedValue = cell.getNumericCellValue(); if ("0.00%".equals(cell.getCellStyle().getDataFormatString())) { // Percent editedValue = editedValue * 100; } editedValueString = formatter.formatValueToAtLeastDP(dto, editedValue); } catch (IllegalStateException e) { log.warn( "Table import. Table " + metaData.getTableName() + " Cell at row: " + (row.getRowNum() + 1) + " col: " + (cellIdx + 1) + " current value: " + dto.getValue() + " cell is not numeric. CELL TYPE is " + cell.getCellType() + ". Cannot read cell."); metaData.addWarning( row.getRowNum(), cellIdx, " current value: " + dto.getValue() + " cell is not numeric. CELL TYPE is " + cell.getCellType() + ". Cannot read cell."); } } else if (cell.getCellType() == Cell.CELL_TYPE_STRING) { RichTextString editedValue = cell.getRichStringCellValue(); if (editedValue.getString().isEmpty()) { editedValueString = ""; } else { if (isNumberInString(editedValue.getString())) { editedValueString = editedValue.getString(); } else { log.warn( "Table import. Table " + metaData.getTableName() + " Cell at row: " + (row.getRowNum() + 1) + " col: " + (cellIdx + 1) + " current value: " + dto.getValue() + " data '" + editedValue.getString() + "' is not numeric. CELL TYPE is " + cell.getCellType()); } } } else if (cell.getCellType() == Cell.CELL_TYPE_BLANK) { editedValueString = ""; } else { log.warn( "Table import. Table " + metaData.getTableName() + " Cell at row: " + (row.getRowNum() + 1) + " col: " + (cellIdx + 1) + " current value: " + dto.getValue() + " cell is not numeric. CELL TYPE is " + cell.getCellType()); } return editedValueString; }