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


Java Cell.getCellTypeEnum方法代码示例

本文整理汇总了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()
        )
    );
}
 
开发者ID:jedcua,项目名称:Parseux,代码行数:25,代码来源:ExcelIterator.java

示例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;
}
 
开发者ID:ozlerhakan,项目名称:poiji,代码行数:9,代码来源:HSSFUnmarshaller.java

示例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;
}
 
开发者ID:Crab2died,项目名称:Excel4J,代码行数:33,代码来源:Utils.java

示例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));
    }
}
 
开发者ID:mattvickery,项目名称:dsMatch,代码行数:28,代码来源:AbstractDataSourceModelTransformer.java

示例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 "";
    }
}
 
开发者ID:IntegrityVision,项目名称:Purchase-order-process-template,代码行数:13,代码来源:MSExcel.java

示例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 "";
	}
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:9,代码来源:XLSProjector.java

示例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;
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:43,代码来源:ExcelReader.java

示例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();
	} 
}
 
开发者ID:21ca,项目名称:selenium-testng-template,代码行数:12,代码来源:FileUtils.java

示例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);
    }
}
 
开发者ID:TFyre,项目名称:vaadin-gridexport,代码行数:33,代码来源:ExcelExport.java

示例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);
    }
}
 
开发者ID:HY-ZhengWei,项目名称:hy.common.report,代码行数:74,代码来源:JavaToExcel.java

示例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;
}
 
开发者ID:Stwissel,项目名称:Excel2XML,代码行数:41,代码来源:E2xCmdline.java

示例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;
}
 
开发者ID:HY-ZhengWei,项目名称:hy.common.report,代码行数:80,代码来源:ExcelHelp.java


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