当前位置: 首页>>代码示例>>Java>>正文


Java CellType类代码示例

本文整理汇总了Java中org.apache.poi.ss.usermodel.CellType的典型用法代码示例。如果您正苦于以下问题:Java CellType类的具体用法?Java CellType怎么用?Java CellType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CellType类属于org.apache.poi.ss.usermodel包,在下文中一共展示了CellType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCellValue

import org.apache.poi.ss.usermodel.CellType; //导入依赖的package包/类
/**
 * 获取单元格的值
 * 
 * @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;
}
 
开发者ID:color-coding,项目名称:btulz.transforms,代码行数:27,代码来源:ExcelParser.java

示例2: getCellTypeEnum

import org.apache.poi.ss.usermodel.CellType; //导入依赖的package包/类
/**
 * 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 + "'");
  }
}
 
开发者ID:monitorjbl,项目名称:excel-streaming-reader,代码行数:25,代码来源:StreamingCell.java

示例3: readCellByType

import org.apache.poi.ss.usermodel.CellType; //导入依赖的package包/类
/**
 * readCellByType is used because CELL_TYPE_FORMULA can be CELL_TYPE_NUMERIC, CELL_TYPE_NUMERIC(date) or CELL_TYPE_STRING.
 *
 * @param cellcell
 *            read (line and column)
 * @param type
 *            CELL_TYPE_FORMULA can be CELL_TYPE_NUMERIC, CELL_TYPE_NUMERIC(date) or CELL_TYPE_STRING
 * @return a string with the data (evalued if CELL_TYPE_FORMULA)
 */
private String readCellByType(Cell cell, CellType type) {
    String txt = "";
    if (cell != null) {
        switch (type) {
            case NUMERIC:
                txt = dateOrNumberProcessing(cell);
                break;
            case STRING:
                txt = String.valueOf(cell.getRichStringCellValue());
                logger.debug("CELL_TYPE_STRING: {}", txt);
                break;
            case FORMULA:
                txt = readCellByType(cell, cell.getCachedFormulaResultTypeEnum());
                logger.debug("CELL_TYPE_FORMULA: {}", txt);
                break;
            case BLANK:
                logger.debug("CELL_TYPE_BLANK (we do nothing)");
                break;
            default:
                logger.error(Messages.getMessage(EXCEL_DATA_PROVIDER_WRONG_CELL_TYPE_ERROR_MESSAGE), type);
                break;
        }
    }
    return txt;
}
 
开发者ID:NoraUi,项目名称:NoraUi,代码行数:35,代码来源:ExcelDataProvider.java

示例4: create

import org.apache.poi.ss.usermodel.CellType; //导入依赖的package包/类
private static void create(Stream<?> stream, Row row) {
    AtomicInteger counter = new AtomicInteger();
    stream.forEach(value -> {
        if (value != null) {
            if (value instanceof String) {
                row.createCell(counter.getAndIncrement(), CellType.STRING).setCellValue((String) value);
            } else if (value instanceof Number) {
                row.createCell(counter.getAndIncrement(), CellType.NUMERIC).setCellValue(((Number) value).doubleValue());
            } else if (value instanceof Boolean) {
                row.createCell(counter.getAndIncrement(), CellType.BOOLEAN).setCellValue((Boolean) value);
            } else if (value instanceof Date) {
                row.createCell(counter.getAndIncrement(), CellType.NUMERIC).setCellValue((Date) value);
            } else if (value instanceof Calendar) {
                row.createCell(counter.getAndIncrement(), CellType.NUMERIC).setCellValue((Calendar) value);
            } else {
                row.createCell(counter.getAndIncrement(), CellType.ERROR);
            }
        } else {
            row.createCell(counter.getAndIncrement(), CellType.BLANK);
        }
    });
}
 
开发者ID:zjnu-acm,项目名称:judge,代码行数:23,代码来源:ExcelUtil.java

示例5: extract

import org.apache.poi.ss.usermodel.CellType; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:FutureCitiesCatapult,项目名称:TomboloDigitalConnector,代码行数:26,代码来源:RowCellExtractor.java

示例6: CellSettings

import org.apache.poi.ss.usermodel.CellType; //导入依赖的package包/类
public CellSettings(
	CellType cellType,
	HSSFCellStyle cellStyle,
	Object cellValue,
	String formula,
	Hyperlink link
	) 
{
	this.cellType = cellType;
	this.cellStyle = cellStyle;
	this.cellValue = cellValue;
	this.formula = formula;
	this.link = link;
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:15,代码来源:JRXlsMetadataExporter.java

示例7: importValues

import org.apache.poi.ss.usermodel.CellType; //导入依赖的package包/类
public void importValues(				
	CellType cellType,
	HSSFCellStyle cellStyle,
	Object cellValue,
	String formula,
	Hyperlink link
	) 
{
	this.cellType = cellType;
	this.cellStyle = cellStyle;
	this.cellValue = cellValue;
	this.formula = formula;
	this.link = link;
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:15,代码来源:JRXlsMetadataExporter.java

示例8: getStringValue

import org.apache.poi.ss.usermodel.CellType; //导入依赖的package包/类
public static String getStringValue(Cell cell) {
	switch (cell.getCellTypeEnum()) {
	case BOOLEAN:
		return cell.getBooleanCellValue() ? "1" : "0";
	case FORMULA:
		return cell.getCellFormula();
	case NUMERIC:
		cell.setCellType(CellType.STRING);
		return cell.getStringCellValue();
	case STRING:
		return cell.getStringCellValue();
	default:
		return "";
	}

}
 
开发者ID:leiyong0326,项目名称:phone,代码行数:17,代码来源:ExcelUtil.java

示例9: getCellData

import org.apache.poi.ss.usermodel.CellType; //导入依赖的package包/类
/**
 * Get Cell Data
 * 
 * @param cell
 * @return cellData
 */
@SuppressWarnings("deprecation")
private String getCellData(Cell cell) {
    /* Return Cell Type */
    CellType cellType = cell.getCellTypeEnum();

    /* Get Data */
    switch (cellType) {
        case BOOLEAN:
            return String.valueOf(cell.getBooleanCellValue());

        case NUMERIC:
            return String.valueOf(cell.getNumericCellValue());

        case STRING:
            return cell.getStringCellValue();

        case BLANK:
            return new String();

        default:
            return new String();
    }
}
 
开发者ID:agrawroh,项目名称:selemize,代码行数:30,代码来源:DefaultPrinter.java

示例10: ExpowCellLib

import org.apache.poi.ss.usermodel.CellType; //导入依赖的package包/类
public ExpowCellLib(int rowIndex, int columnIndex, CellType cellType, String value) {
	// 
	this.x = columnIndex; 
	this.y = rowIndex; 
	this.value = value;
	this.type = cellType;
	if (getCellTypeAsStr().equals(BadCellType)) {
		throw new IllegalArgumentException(
				String.format("Cell type is not valid:%d", 
						cellType));
	}
	
	if (value == null) {
		throw new IllegalArgumentException(
				String.format("Cell value can't be null."));
	}
}
 
开发者ID:nextreesoft,项目名称:expow,代码行数:18,代码来源:ExpowCellLib.java

示例11: testGetCellTypeAsStr

import org.apache.poi.ss.usermodel.CellType; //导入依赖的package包/类
@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());
}
 
开发者ID:nextreesoft,项目名称:expow,代码行数:22,代码来源:ExpowCellLibTest.java

示例12: parseRow

import org.apache.poi.ss.usermodel.CellType; //导入依赖的package包/类
/**
 * 行単位で解析し、必要なら改ページを挿入する
 */
protected void parseRow( Sheet sheet, SheetParser sheetParser, SheetData sheetData, Row row, int rowIndex) {
    int firstColNum = row.getFirstCellNum();
    int lastColNum = row.getLastCellNum() - 1;

    for ( int colIndex = firstColNum; colIndex <= lastColNum; colIndex++) {
        Cell cell = row.getCell( colIndex);
        if ( cell != null) {
            if ( cell.getCellTypeEnum() == CellType.STRING && cell.getStringCellValue().contains( BreakParamParser.DEFAULT_TAG)) {
                // 改ページを挿入
                if ( isInMergedRegion( sheet, row, cell)) {
                    setRowBreakMergedRegion( sheet, row, cell);
                } else {
                    setRowBreak( sheet, row, cell);
                }
            }
        }
    }

}
 
开发者ID:excella-core,项目名称:excella-reports,代码行数:23,代码来源:BreakAdapter.java

示例13: getBlockCellType

import org.apache.poi.ss.usermodel.CellType; //导入依赖的package包/类
/**
 * 対象シートの指定された範囲のセルのタイプ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;
}
 
开发者ID:excella-core,项目名称:excella-reports,代码行数:31,代码来源:ReportsUtil.java

示例14: isEmptyRow

import org.apache.poi.ss.usermodel.CellType; //导入依赖的package包/类
/**
 * 行に情報(値、スタイル、タイプ)が設定されているかどうかの判定を行う
 * 
 * @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;
}
 
开发者ID:excella-core,项目名称:excella-reports,代码行数:32,代码来源:ReportsUtil.java

示例15: isEmptyCell

import org.apache.poi.ss.usermodel.CellType; //导入依赖的package包/类
/**
 * セルに情報(値、スタイル、タイプ)が設定されているかどうかの判定を行う
 * 
 * @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;
}
 
开发者ID:excella-core,项目名称:excella-reports,代码行数:26,代码来源:ReportsUtil.java


注:本文中的org.apache.poi.ss.usermodel.CellType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。