本文整理匯總了Java中org.apache.poi.ss.usermodel.Cell.getCellTypeEnum方法的典型用法代碼示例。如果您正苦於以下問題:Java Cell.getCellTypeEnum方法的具體用法?Java Cell.getCellTypeEnum怎麽用?Java Cell.getCellTypeEnum使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.ss.usermodel.Cell
的用法示例。
在下文中一共展示了Cell.getCellTypeEnum方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: extractCellValue
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
/**
* Attempts to convert a {@link Cell} to {@link String}, if it fails,
* it throws {@link IllegalStateException} with message
*
* @param cell to convert to string
* @return String value of cell
*/
private String extractCellValue(Cell cell) {
switch (cell.getCellTypeEnum()) {
case STRING:
return cell.getStringCellValue();
case NUMERIC:
return String.valueOf(cell.getNumericCellValue());
}
throw new IllegalStateException(
String.format(
"No string conversion defined for sheet %s, cell %s with type %s",
cell.getSheet().getSheetName(),
cell.getAddress().formatAsString(),
cell.getCellTypeEnum().toString()
)
);
}
示例2: isRowEmpty
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
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;
}
示例3: getCellValue
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
/**
* 獲取單元格內容
*
* @param c 單元格
* @return 單元格內容
*/
public static String getCellValue(Cell c) {
String o;
switch (c.getCellTypeEnum()) {
case BLANK:
o = "";
break;
case BOOLEAN:
o = String.valueOf(c.getBooleanCellValue());
break;
case FORMULA:
o = calculationFormula(c);
break;
case NUMERIC:
o = String.valueOf(c.getNumericCellValue());
o = matchDoneBigDecimal(o);
o = RegularUtils.converNumByReg(o);
break;
case STRING:
o = c.getStringCellValue();
break;
default:
o = null;
break;
}
return o;
}
示例4: cellToFieldDefinitionTransformer
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
private Optional<DataSourceFieldDefinition<?>> cellToFieldDefinitionTransformer(final Cell headerCell,
final Row dataRow) {
notNull(headerCell, "Mandatory argument 'headerCell' is missing.");
notNull(dataRow, "Mandatory argument 'dataRow' is missing.");
final Cell cell = dataRow.getCell(headerCell.getColumnIndex());
switch (cell.getCellTypeEnum()) {
case BOOLEAN:
return Optional.of(
new DefaultDataSourceFieldDefinition<>(headerCell.getStringCellValue(), Boolean.class));
case NUMERIC:
if (cellAppearsToBeADateType(headerCell, cell))
return Optional.of(
new DefaultDataSourceFieldDefinition<>(headerCell.getStringCellValue(), Date.class));
return Optional.of(
new DefaultDataSourceFieldDefinition<>(headerCell.getStringCellValue(), BigDecimal.class));
case FORMULA:
case ERROR:
throw new IllegalStateException("Cell type not supported:" + cell.getCellTypeEnum());
case STRING:
case BLANK:
case _NONE:
default:
return Optional.of(
new DefaultDataSourceFieldDefinition<>(headerCell.getStringCellValue(), String.class));
}
}
示例5: getAsString
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
private String getAsString(Cell cell) {
switch (cell.getCellTypeEnum()) {
case NUMERIC:
return String.valueOf(cell.getNumericCellValue());
case BOOLEAN:
return String.valueOf(cell.getBooleanCellValue());
case STRING:
return cell.getStringCellValue();
default:
return "";
}
}
示例6: getCellText
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
private static String getCellText(Cell cell) {
switch (cell.getCellTypeEnum()) {
case STRING: return cell.getStringCellValue();
case BOOLEAN: return Boolean.toString(cell.getBooleanCellValue());
case NUMERIC: return Double.toString(cell.getNumericCellValue());
default: return "";
}
}
示例7: getCellValue
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
/**
* 獲取指定單元格的值
*
* @param rowNumber 行數,從1開始
* @param cellNumber 列數,從1開始
* @return 該單元格的值
*/
public String getCellValue(int rowNumber, int cellNumber) {
String result;
checkRowAndCell(rowNumber, cellNumber);
Sheet sheet = this.workbook.getSheet(this.sheetName);
Row row = sheet.getRow(--rowNumber);
Cell cell = row.getCell(--cellNumber);
switch (cell.getCellTypeEnum()) {
case BLANK:
result = cell.getStringCellValue();
break;
case BOOLEAN:
result = String.valueOf(cell.getBooleanCellValue());
break;
case ERROR:
result = String.valueOf(cell.getErrorCellValue());
break;
case FORMULA:
result = cell.getCellFormula();
break;
case NUMERIC:
if (DateUtil.isCellDateFormatted(cell)) {
result = format.format(cell.getDateCellValue());
} else {
result = String.valueOf(cell.getNumericCellValue());
}
break;
case STRING:
result = cell.getRichStringCellValue().getString();
break;
default:
result = cell.getStringCellValue();
break;
}
return result;
}
示例8: getCellString
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
private static String getCellString(Cell cell) {
if (cell.getCellTypeEnum() == CellType.FORMULA) {
try {
return String.valueOf(cell.getNumericCellValue());
} catch (Exception e) {
return cell.getRichStringCellValue().toString();
}
} else {
return cell.toString();
}
}
示例9: finalSheetFormat
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
/**
* Final formatting of the sheet upon completion of writing the data. For
* example, we can only size the column widths once the data is in the
* report and the sheet knows how wide the data is.
*/
protected void finalSheetFormat() {
final FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
if (isHierarchical()) {
/*
* evaluateInCell() is equivalent to paste special -> value. The formula refers to cells
* in the other sheet we are going to delete. We sum in the other sheet because if we
* summed in the main sheet, we would double count. Subtotal with hidden rows is not yet
* implemented in POI.
*/
for (final Row r : sheet) {
for (final Cell c : r) {
if (c.getCellTypeEnum() == CellType.FORMULA) {
evaluator.evaluateInCell(c);
}
}
}
workbook.setActiveSheet(workbook.getSheetIndex(sheet));
if (hierarchicalTotalsSheet != null) {
workbook.removeSheetAt(workbook.getSheetIndex(hierarchicalTotalsSheet));
}
} else {
evaluator.evaluateAll();
}
for (int col = 0; col < getPropIds().size(); col++) {
sheet.autoSizeColumn(col);
}
}
示例10: copyCellByBlankSpace
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
/**
* 複製單位格(空白行的複製,即隻複製格式和固定文字,不填充數據)
*
* @author ZhengWei(HY)
* @createDate 2017-07-03
* @version v1.0
*
* @param i_RTemplate 模板對象
* @param i_TemplateCell 模板中的單元格對象
* @param i_DataWorkbook 數據工作薄
* @param i_DataCell 數據中的單元格對象
* @param io_RSystemValue 係統變量信息
* @param i_Datas 本行對應的數據
* @param io_RValue 小計循環的迭代器
* @return
*/
public final static void copyCellByBlankSpace(RTemplate i_RTemplate ,Cell i_TemplateCell ,RWorkbook i_DataWorkbook ,Cell i_DataCell ,RSystemValue io_RSystemValue)
{
// 複製樣式
i_DataCell.setCellStyle(i_DataWorkbook.getCellStyle(i_RTemplate ,i_TemplateCell.getCellStyle().getIndex()));
// 複製評論
copyComment(i_RTemplate ,i_TemplateCell ,i_DataWorkbook ,i_DataCell);
// 複製數據類型
CellType v_CellType = i_TemplateCell.getCellTypeEnum();
// i_DataCell.setCellType(v_CellType); 不能在此統一設置,原因是:下麵代碼對類型是有浮動的
if ( v_CellType == CellType.NUMERIC )
{
i_DataCell.setCellType(v_CellType);
if ( HSSFDateUtil.isCellDateFormatted(i_TemplateCell) )
{
i_DataCell.setCellValue(i_TemplateCell.getDateCellValue());
}
else
{
i_DataCell.setCellValue(i_TemplateCell.getNumericCellValue());
}
}
else if ( v_CellType == CellType.STRING )
{
RichTextString v_TemplateRichText = i_TemplateCell.getRichStringCellValue();
String v_ValueName = v_TemplateRichText.toString();
if ( i_RTemplate.isExists(v_ValueName) )
{
i_DataCell.setCellType(v_CellType);
i_DataCell.setCellValue("");
}
else
{
i_DataCell.setCellType(v_CellType);
copyRichTextStyle(i_RTemplate ,v_TemplateRichText ,i_DataWorkbook ,i_DataCell);
}
}
else if ( v_CellType == CellType.BOOLEAN )
{
i_DataCell.setCellType(v_CellType);
i_DataCell.setCellValue(i_TemplateCell.getBooleanCellValue());
}
else if ( v_CellType == CellType.FORMULA)
{
i_DataCell.setCellType(v_CellType);
i_DataCell.setCellFormula(i_TemplateCell.getCellFormula());
}
else
{
// Nothing.
i_DataCell.setCellType(v_CellType);
}
}
示例11: getCellValue
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
private String getCellValue(final Cell cell, int count) {
String cellValue = null;
CellType ct = cell.getCellTypeEnum();
switch (ct) {
case STRING:
cellValue = cell.getStringCellValue();
break;
case NUMERIC:
cellValue = String.valueOf(cell.getNumericCellValue());
break;
case BOOLEAN:
cellValue = String.valueOf(cell.getBooleanCellValue());
break;
case BLANK:
if (count > -1) {
cellValue = "BLANK" + String.valueOf(count);
}
break;
case FORMULA:
CellType cacheCellType = cell.getCachedFormulaResultTypeEnum(); {
switch (cacheCellType) {
case STRING:
cellValue = cell.getStringCellValue();
break;
case NUMERIC:
cellValue = String.valueOf(cell.getNumericCellValue());
break;
case BOOLEAN:
cellValue = String.valueOf(cell.getBooleanCellValue());
break;
default:
cellValue = cell.getCellFormula();
}
}
break;
default:
cellValue = null;
}
return cellValue;
}
示例12: readDatas
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
public final static PartitionMap<String ,RCell> readDatas(Sheet i_Sheet ,Integer i_BeginRow ,Integer i_EndRow)
{
PartitionMap<String ,RCell> v_Ret = new TablePartition<String ,RCell>();
Sheet v_Sheet = i_Sheet;
int v_BeginRow = 0;
int v_EndRow = 0;
if ( i_BeginRow != null )
{
v_BeginRow = i_BeginRow.intValue();
if ( v_BeginRow < 0 )
{
v_BeginRow = 0;
}
}
if ( i_EndRow != null )
{
v_EndRow = i_EndRow.intValue();
}
else
{
v_EndRow = v_Sheet.getPhysicalNumberOfRows();
}
for (int v_RowNo=v_BeginRow; v_RowNo<=v_EndRow; v_RowNo++)
{
Row v_Row = v_Sheet.getRow(v_RowNo);
if ( v_Row == null )
{
continue;
}
short v_CellCount = v_Row.getLastCellNum();
for (int v_ColumnNo=0; v_ColumnNo<v_CellCount; v_ColumnNo++)
{
Cell v_Cell = v_Row.getCell(v_ColumnNo);
if ( v_Cell == null )
{
continue;
}
if ( v_Cell.getCellTypeEnum() == CellType.STRING )
{
String v_Value = v_Cell.getStringCellValue();
if ( !Help.isNull(v_Value) )
{
RCell v_RCell = new RCell(v_RowNo ,v_ColumnNo);
List<String> v_Decimals = StringHelp.getString(v_Cell.getCellStyle().getDataFormatString() ,$Decimal);
if ( !Help.isNull(v_Decimals) )
{
v_RCell.setDecimal(v_Decimals.get(0).split("\\.")[1].length());
}
v_Ret.putRow(v_Value.trim() ,v_RCell);
}
}
else if ( v_Cell.getCellTypeEnum() == CellType.NUMERIC )
{
if ( HSSFDateUtil.isCellDateFormatted(v_Cell) )
{
if ( v_Cell.getDateCellValue() != null )
{
v_Ret.putRow((new Date(v_Cell.getDateCellValue())).getFull() ,new RCell(v_RowNo ,v_ColumnNo));
}
}
else
{
v_Ret.putRow(String.valueOf(v_Cell.getNumericCellValue()) ,new RCell(v_RowNo ,v_ColumnNo));
}
}
}
}
return v_Ret;
}