本文整理汇总了Java中org.apache.poi.ss.usermodel.CellType.BLANK属性的典型用法代码示例。如果您正苦于以下问题:Java CellType.BLANK属性的具体用法?Java CellType.BLANK怎么用?Java CellType.BLANK使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.poi.ss.usermodel.CellType
的用法示例。
在下文中一共展示了CellType.BLANK属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCellValue
/**
* 获取单元格的值
*
* @param cell
* @return
*/
public static Object getCellValue(Cell cell) {
Object cellValue = null;
CellType cellType = cell.getCellTypeEnum();// CellType.forInt(cell.getCellType());
if (cellType == CellType.STRING) {
cellValue = cell.getStringCellValue();
} else if (cellType == CellType.NUMERIC) {
if (DateUtil.isCellDateFormatted(cell)) {
cellValue = cell.getDateCellValue();
} else {
cellValue = cell.getNumericCellValue();
}
} else if (cellType == CellType.BOOLEAN) {
cellValue = cell.getBooleanCellValue();
} else if (cellType == CellType.FORMULA) {
cellValue = cell.getCellFormula();
} else if (cellType == CellType.BLANK) {
cellValue = "";
}
return cellValue;
}
示例2: getCellTypeEnum
/**
* Return the cell type.
*
* @return the cell type
* Will be renamed to <code>getCellType()</code> when we make the CellType enum transition in POI 4.0. See bug 59791.
*/
@Override
public CellType getCellTypeEnum() {
if(contentsSupplier.getContent() == null || type == null) {
return CellType.BLANK;
} else if("n".equals(type)) {
return CellType.NUMERIC;
} else if("s".equals(type) || "inlineStr".equals(type)) {
return CellType.STRING;
} else if("str".equals(type)) {
return CellType.FORMULA;
} else if("b".equals(type)) {
return CellType.BOOLEAN;
} else if("e".equals(type)) {
return CellType.ERROR;
} else {
throw new UnsupportedOperationException("Unsupported cell type '" + type + "'");
}
}
示例3: extract
@Override
public String extract() throws ExtractorException {
if (row == null)
throw new BlankCellException("Empty row");
if (row.getCell(columnId) == null)
throw new ExtractorException("Column with index "+columnId+" does not exit");
if (row.getCell(columnId).getCellTypeEnum() == CellType.BLANK)
throw new BlankCellException("Empty cell value");
try{
switch (cellType) {
case BOOLEAN:
return String.valueOf(row.getCell(columnId).getBooleanCellValue());
case NUMERIC:
return String.valueOf(row.getCell(columnId).getNumericCellValue());
case STRING:
return String.valueOf(row.getCell(columnId).getStringCellValue());
default:
throw new ExtractorException("Unhandled cell type: "+cellType);
}
}catch (IllegalStateException e){
// Most likely trying to read a non-numeric value like '--'
// Hence we treat this as a blank cell
throw new BlankCellException("Could not extract value", e);
}
}
示例4: testGetCellTypeAsStr
@Test
public void testGetCellTypeAsStr() throws Exception {
//
ExpowCellLib cell = new ExpowCellLib(0, 0, CellType.STRING, "StringValue");
assertEquals("CELL_TYPE_STRING", cell.getCellTypeAsStr());
cell = new ExpowCellLib(0, 0, CellType.BLANK, "");
assertEquals("CELL_TYPE_BLANK", cell.getCellTypeAsStr());
cell = new ExpowCellLib(0, 0, CellType.BOOLEAN, "true");
assertEquals("CELL_TYPE_BOOLEAN", cell.getCellTypeAsStr());
cell = new ExpowCellLib(0, 0, CellType.ERROR, "");
assertEquals("CELL_TYPE_ERROR", cell.getCellTypeAsStr());
cell = new ExpowCellLib(0, 0, CellType.FORMULA, "");
assertEquals("CELL_TYPE_FORMULA", cell.getCellTypeAsStr());
cell = new ExpowCellLib(0, 0, CellType.NUMERIC, "");
assertEquals("CELL_TYPE_NUMERIC", cell.getCellTypeAsStr());
}
示例5: getBlockCellType
/**
* 対象シートの指定された範囲のセルのタイプint[行番号][列番号]の形式で取得する。 セルの値がnullの場合、Cell.CELL_TYPE_BLANKがセットされる。
*
* @param sheet 対象となるシート
* @param bStartRowIndex 範囲開始行番号
* @param bEndRowIndex 範囲終了行番号
* @param bStartColIndex 範囲開始列番号
* @param bEndColIndex 範囲終了列番号
* @return セルのタイプ
*/
public static CellType[][] getBlockCellType( Sheet sheet, int bStartRowIndex, int bEndRowIndex, int bStartColIndex, int bEndColIndex) {
CellType[][] blockCellType = new CellType[bEndRowIndex - bStartRowIndex + 1][bEndColIndex - bStartColIndex + 1];
int rowIdx = 0;
for ( int bRowIndex = bStartRowIndex; bRowIndex <= bEndRowIndex; bRowIndex++) {
int colIdx = 0;
for ( int bColIndex = bStartColIndex; bColIndex <= bEndColIndex; bColIndex++) {
Row row = sheet.getRow( bRowIndex);
if ( row != null && row.getCell( bColIndex) != null) {
blockCellType[rowIdx][colIdx] = row.getCell( bColIndex).getCellTypeEnum();
} else {
blockCellType[rowIdx][colIdx] = CellType.BLANK;
}
colIdx++;
}
rowIdx++;
}
return blockCellType;
}
示例6: isEmptyRow
/**
* 行に情報(値、スタイル、タイプ)が設定されているかどうかの判定を行う
*
* @param rowCellTypes 対象行のセルスタイル
* @param rowCellValues 対象行のセルの値
* @param rowCellStyles 対象行のセルタイプ
* @return 行が空の場合はtrue、行に何らかの情報を持っている場合はfalse
*/
public static boolean isEmptyRow( CellType[] rowCellTypes, Object[] rowCellValues, CellStyle[] rowCellStyles) {
// CellTypeの空判定 BLANKなら空とみなす
for ( CellType cellType : rowCellTypes) {
if ( cellType != CellType.BLANK) {
return false;
}
}
// 値の空判定 nullなら空とみなす
for ( Object cellValue : rowCellValues) {
if ( cellValue != null) {
return false;
}
}
// CellStyleの空判定 nullなら空とみなす
for ( CellStyle cellStyle : rowCellStyles) {
if ( cellStyle != null) {
return false;
}
}
return true;
}
示例7: isEmptyCell
/**
* セルに情報(値、スタイル、タイプ)が設定されているかどうかの判定を行う
*
* @param cellType 対象セルのスタイル
* @param cellValue 対象セルの値
* @param cellStyle 対象セルのタイプ
* @return セルが空の場合はtrue、セルに何らかの情報を持っている場合はfalse
*/
public static boolean isEmptyCell( CellType cellType, Object cellValue, CellStyle cellStyle) {
// CellTypeの空判定 BLANKなら空とみなす
if ( cellType != CellType.BLANK) {
return false;
}
// 値の空判定 nullなら空とみなす
if ( cellValue != null) {
return false;
}
// CellStyleの空判定 nullなら空とみなす
if ( cellStyle != null) {
return false;
}
return true;
}
示例8: getCachedFormulaResultTypeEnum
/**
* Not supported
*/
@Override
public CellType getCachedFormulaResultTypeEnum() {
if (type != null && "str".equals(type)) {
if(contentsSupplier.getContent() == null || cachedFormulaResultType == null) {
return CellType.BLANK;
} else if("n".equals(cachedFormulaResultType)) {
return CellType.NUMERIC;
} else if("s".equals(cachedFormulaResultType) || "inlineStr".equals(cachedFormulaResultType)) {
return CellType.STRING;
} else if("str".equals(cachedFormulaResultType)) {
return CellType.FORMULA;
} else if("b".equals(cachedFormulaResultType)) {
return CellType.BOOLEAN;
} else if("e".equals(cachedFormulaResultType)) {
return CellType.ERROR;
} else {
throw new UnsupportedOperationException("Unsupported cell type '" + cachedFormulaResultType + "'");
}
}
else {
throw new IllegalStateException("Only formula cells have cached results");
}
}
示例9: isRowEmpty
private boolean isRowEmpty(Row row) {
for (int c = row.getFirstCellNum(); c < row.getLastCellNum(); c++) {
Cell cell = row.getCell(c, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
if (cell != null && cell.getCellTypeEnum() != CellType.BLANK)
return false;
}
return true;
}
示例10: canBeReadAsNumericCell
public static boolean canBeReadAsNumericCell (@Nullable final Cell aCell)
{
if (aCell == null)
return false;
final CellType eType = aCell.getCellTypeEnum ();
return eType == CellType.BLANK || eType == CellType.NUMERIC || eType == CellType.FORMULA;
}
示例11: getCell
/**
* {@inheritDoc}
*/
@Override
public Cell getCell(int cellnum, MissingCellPolicy policy) {
StreamingCell cell = (StreamingCell) cellMap.get(cellnum);
if(policy == MissingCellPolicy.CREATE_NULL_AS_BLANK) {
if(cell == null) { return new StreamingCell(cellnum, rowIndex, false); }
} else if(policy == MissingCellPolicy.RETURN_BLANK_AS_NULL) {
if(cell == null || cell.getCellTypeEnum() == CellType.BLANK) { return null; }
}
return cell;
}
示例12: loadWorkbook
private void loadWorkbook(Workbook workbook) {
String cellValue = null;
for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
Sheet sheet = workbook.getSheetAt(i);
System.out.println("sheet: " + workbook.getSheetName(i));
// 有效值
List<? extends DataValidation> dataValidations = sheet.getDataValidations();
if (dataValidations != null && dataValidations.size() > 0) {
System.out.println("data validations: ");
for (DataValidation validation : dataValidations) {
System.out.println(validation.toString());
}
}
// 表格行
for (Row row : sheet) {
// 行单元格
for (Cell cell : row) {
cellValue = "";
CellType cellType = cell.getCellTypeEnum();// CellType.forInt(cell.getCellType());
if (cellType == CellType.STRING) {
cellValue = cell.getRichStringCellValue().getString();
} else if (cellType == CellType.NUMERIC) {
if (DateUtil.isCellDateFormatted(cell)) {
cellValue = String.valueOf(cell.getDateCellValue());
} else {
cellValue = String.valueOf(cell.getNumericCellValue());
}
} else if (cellType == CellType.BOOLEAN) {
cellValue = String.valueOf(cell.getBooleanCellValue());
} else if (cellType == CellType.FORMULA) {
cellValue = String.valueOf(cell.getCellFormula());
} else if (cellType == CellType.BLANK) {
cellValue = String.valueOf(" ");
}
System.out.print(cellValue);
System.out.print(" ");
}
System.out.println("");
}
}
}
示例13: CellSettings
public CellSettings(HSSFCellStyle cellStyle)
{
this(CellType.BLANK, cellStyle, null);
}