Java Code Examples for org.apache.poi.hssf.usermodel.HSSFCell#CELL_TYPE_ERROR
The following examples show how to use
org.apache.poi.hssf.usermodel.HSSFCell#CELL_TYPE_ERROR .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenerateDoc.java From danyuan-application with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") private static XSSFSheet copySheet(XSSFSheet sheetFrom, XSSFSheet sheetTo) { // 初期化 CellRangeAddress region = null; Row rowFrom = null; Row rowTo = null; Cell cellFrom = null; Cell cellTo = null; // セル結合のコピー for (int i = 0; i < sheetFrom.getNumMergedRegions(); i++) { region = sheetFrom.getMergedRegion(i); if ((region.getFirstColumn() >= sheetFrom.getFirstRowNum()) && (region.getLastRow() <= sheetFrom.getLastRowNum())) { sheetTo.addMergedRegion(region); } } // セルのコピー for (int intRow = sheetFrom.getFirstRowNum(); intRow <= sheetFrom.getLastRowNum(); intRow++) { rowFrom = sheetFrom.getRow(intRow); rowTo = sheetTo.createRow(intRow); if (null == rowFrom) { continue; } rowTo.setHeight(rowFrom.getHeight()); for (int intCol = 0; intCol < rowFrom.getLastCellNum(); intCol++) { // セル幅のコピー sheetTo.setDefaultColumnStyle(intCol, sheetFrom.getColumnStyle(intCol)); sheetTo.setColumnWidth(intCol, sheetFrom.getColumnWidth(intCol)); cellFrom = rowFrom.getCell(intCol); cellTo = rowTo.createCell(intCol); if (null == cellFrom) { continue; } // セルスタイルとタイプのコピー cellTo.setCellStyle(cellFrom.getCellStyle()); cellTo.setCellType(cellFrom.getCellType()); // タイトル内容のコピー // 不同数据类型处理 int cellFromType = cellFrom.getCellType(); cellTo.setCellType(cellFromType); if (cellFromType == HSSFCell.CELL_TYPE_NUMERIC) { if (HSSFDateUtil.isCellDateFormatted(cellFrom)) { cellTo.setCellValue(cellFrom.getDateCellValue()); } else { cellTo.setCellValue(cellFrom.getNumericCellValue()); } } else if (cellFromType == HSSFCell.CELL_TYPE_STRING) { cellTo.setCellValue(cellFrom.getRichStringCellValue()); } else if (cellFromType == HSSFCell.CELL_TYPE_BLANK) { // nothing21 } else if (cellFromType == HSSFCell.CELL_TYPE_BOOLEAN) { cellTo.setCellValue(cellFrom.getBooleanCellValue()); } else if (cellFromType == HSSFCell.CELL_TYPE_ERROR) { cellTo.setCellErrorValue(cellFrom.getErrorCellValue()); } else if (cellFromType == HSSFCell.CELL_TYPE_FORMULA) { cellTo.setCellFormula(cellFrom.getCellFormula()); } else { // nothing29 } } } // 枠線の設定 sheetTo.setDisplayGridlines(false); // sheetTo.setDisplayGuts(true); // sheetTo.setDisplayRowColHeadings(true); // 剪切 // sheetTo.shiftRows(13, 15, 31, false, false, false); // Excelのズーム設定 sheetTo.setZoom(85, 100); // シートを戻る。 return sheetTo; }
Example 2
Source File: ExcelOperator.java From minsx-framework with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") private static String getCellData(Cell cell) { String value = null; if (cell == null) { return null; } switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_STRING: value = cell.getStringCellValue(); break; case HSSFCell.CELL_TYPE_FORMULA: value = cell.getCellFormula(); break; case HSSFCell.CELL_TYPE_NUMERIC: HSSFDataFormatter dataFormatter = new HSSFDataFormatter(); value = dataFormatter.formatCellValue(cell); break; case HSSFCell.CELL_TYPE_BLANK: value = null; break; case HSSFCell.CELL_TYPE_ERROR: value = "#ERROR#"; break; } return value; }
Example 3
Source File: PoiUtil.java From dk-fitting with Apache License 2.0 | 5 votes |
/** * 获取单元格中的内容 ,该犯法用于解析各种形式的数据 */ private Object getCellString(HSSFCell cell) { Object result = null; if (cell != null) { int cellType = cell.getCellType(); switch (cellType) { case HSSFCell.CELL_TYPE_STRING: result = cell.getRichStringCellValue().getString(); break; case HSSFCell.CELL_TYPE_NUMERIC: result = cell.getNumericCellValue(); break; case HSSFCell.CELL_TYPE_FORMULA: result = cell.getNumericCellValue(); break; case HSSFCell.CELL_TYPE_ERROR: result = null; break; case HSSFCell.CELL_TYPE_BOOLEAN: result = cell.getBooleanCellValue(); break; case HSSFCell.CELL_TYPE_BLANK: result = null; break; default: break; } } return result; }
Example 4
Source File: ReadExcelUtil.java From DWSurvey with GNU Affero General Public License v3.0 | 5 votes |
public static String getCellStringValue(HSSFCell cell) { String cellValue = ""; switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_STRING: cellValue = cell.getStringCellValue(); if (cellValue.trim().equals("") || cellValue.trim().length() <= 0) { cellValue = " "; } break; case HSSFCell.CELL_TYPE_NUMERIC: // cellValue = String.valueOf(cell.getNumericCellValue()); DecimalFormat formatter = new DecimalFormat("######"); cellValue = formatter.format(cell.getNumericCellValue()); break; case HSSFCell.CELL_TYPE_FORMULA: cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cellValue = String.valueOf(cell.getNumericCellValue()); break; case HSSFCell.CELL_TYPE_BLANK: cellValue = " "; break; case HSSFCell.CELL_TYPE_BOOLEAN: break; case HSSFCell.CELL_TYPE_ERROR: break; default: break; } return cellValue; }
Example 5
Source File: GenerateDoc.java From danyuan-application with Apache License 2.0 | 4 votes |
/** * @方法名 copySheet * @功能 复制sheet * @参数 @param sheetFrom * @参数 @param sheetTo * @参数 @return * @返回 HSSFSheet * @author Administrator * @throws */ @SuppressWarnings("deprecation") private static HSSFSheet copySheet(HSSFSheet sheetFrom, HSSFSheet sheetTo) { // 初期化 CellRangeAddress region = null; Row rowFrom = null; Row rowTo = null; Cell cellFrom = null; Cell cellTo = null; // セル結合のコピー for (int i = 0; i < sheetFrom.getNumMergedRegions(); i++) { region = sheetFrom.getMergedRegion(i); if ((region.getFirstColumn() >= sheetFrom.getFirstRowNum()) && (region.getLastRow() <= sheetFrom.getLastRowNum())) { sheetTo.addMergedRegion(region); } } // セルのコピー for (int intRow = sheetFrom.getFirstRowNum(); intRow <= sheetFrom.getLastRowNum(); intRow++) { rowFrom = sheetFrom.getRow(intRow); rowTo = sheetTo.createRow(intRow); if (null == rowFrom) { continue; } rowTo.setHeight(rowFrom.getHeight()); for (int intCol = 0; intCol < rowFrom.getLastCellNum(); intCol++) { // セル幅のコピー sheetTo.setDefaultColumnStyle(intCol, sheetFrom.getColumnStyle(intCol)); sheetTo.setColumnWidth(intCol, sheetFrom.getColumnWidth(intCol)); cellFrom = rowFrom.getCell(intCol); cellTo = rowTo.createCell(intCol); if (null == cellFrom) { continue; } // セルスタイルとタイプのコピー cellTo.setCellStyle(cellFrom.getCellStyle()); cellTo.setCellType(cellFrom.getCellType()); // タイトル内容のコピー // 不同数据类型处理 int cellFromType = cellFrom.getCellType(); cellTo.setCellType(cellFromType); if (cellFromType == HSSFCell.CELL_TYPE_NUMERIC) { if (HSSFDateUtil.isCellDateFormatted(cellFrom)) { cellTo.setCellValue(cellFrom.getDateCellValue()); } else { cellTo.setCellValue(cellFrom.getNumericCellValue()); } } else if (cellFromType == HSSFCell.CELL_TYPE_STRING) { cellTo.setCellValue(cellFrom.getRichStringCellValue()); } else if (cellFromType == HSSFCell.CELL_TYPE_BLANK) { // nothing21 } else if (cellFromType == HSSFCell.CELL_TYPE_BOOLEAN) { cellTo.setCellValue(cellFrom.getBooleanCellValue()); } else if (cellFromType == HSSFCell.CELL_TYPE_ERROR) { cellTo.setCellErrorValue(cellFrom.getErrorCellValue()); } else if (cellFromType == HSSFCell.CELL_TYPE_FORMULA) { cellTo.setCellFormula(cellFrom.getCellFormula()); } else { // nothing29 } } } // 枠線の設定 sheetTo.setDisplayGridlines(false); // sheetTo.setDisplayGuts(true); // sheetTo.setDisplayRowColHeadings(true); // 剪切 // sheetTo.shiftRows(13, 15, 31, false, false, false); // Excelのズーム設定 sheetTo.setZoom(85, 100); // シートを戻る。 return sheetTo; }
Example 6
Source File: XlsTable.java From Leo with Apache License 2.0 | 4 votes |
public Object getValue(int row, String column) throws DataSetException { if (logger.isDebugEnabled()) logger.debug("getValue(row={}, columnName={}) - start", Integer.toString(row), column); assertValidRowIndex(row); int columnIndex = getColumnIndex(column); HSSFCell cell = _sheet.getRow(row + 1).getCell(columnIndex); if (cell == null) { return null; } int type = cell.getCellType(); switch (type) { case HSSFCell.CELL_TYPE_NUMERIC: HSSFCellStyle style = cell.getCellStyle(); if (HSSFDateUtil.isCellDateFormatted(cell)) { return getDateValue(cell); } else if (XlsDataSetWriter.DATE_FORMAT_AS_NUMBER_DBUNIT.equals(style.getDataFormatString())) { // The special dbunit date format return getDateValueFromJavaNumber(cell); } else { return getNumericValue(cell); } case HSSFCell.CELL_TYPE_STRING: return cell.getRichStringCellValue().getString(); case HSSFCell.CELL_TYPE_FORMULA: throw new DataTypeException("Formula not supported at row=" + row + ", column=" + column); case HSSFCell.CELL_TYPE_BLANK: return null; case HSSFCell.CELL_TYPE_BOOLEAN: return cell.getBooleanCellValue() ? Boolean.TRUE : Boolean.FALSE; case HSSFCell.CELL_TYPE_ERROR: throw new DataTypeException("Error at row=" + row + ", column=" + column); default: throw new DataTypeException("Unsupported type at row=" + row + ", column=" + column); } }