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


Java Cell.getCellFormula方法代码示例

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


在下文中一共展示了Cell.getCellFormula方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCellValue

import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
/**
 * 获取单元格值
 *
 * @param row    获取的行
 * @param column 获取单元格列号
 * @return 单元格值
 */
public Object getCellValue(Row row, int column) {
    Object val = "";
    try {
        Cell cell = row.getCell(column);
        if (cell != null) {
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                // val = cell.getNumericCellValue();
                // 当excel 中的数据为数值或日期是需要特殊处理
                if (HSSFDateUtil.isCellDateFormatted(cell)) {
                    double d = cell.getNumericCellValue();
                    Date date = HSSFDateUtil.getJavaDate(d);
                    SimpleDateFormat dformat = new SimpleDateFormat(
                            "yyyy-MM-dd");
                    val = dformat.format(date);
                } else {
                    NumberFormat nf = NumberFormat.getInstance();
                    nf.setGroupingUsed(false);// true时的格式:1,234,567,890
                    val = nf.format(cell.getNumericCellValue());// 数值类型的数据为double,所以需要转换一下
                }
            } else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
                val = cell.getStringCellValue();
            } else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
                val = cell.getCellFormula();
            } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
                val = cell.getBooleanCellValue();
            } else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) {
                val = cell.getErrorCellValue();
            }
        }
    } catch (Exception e) {
        return val;
    }
    return val;
}
 
开发者ID:sombie007,项目名称:ExcelHandle,代码行数:42,代码来源:ImportExcel.java

示例2: 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

示例3: 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

示例4: read

import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
private List<List<String>> read(Workbook wb, int sheetIndex) {
    List<List<String>> dataLst = Lists.newArrayList();
    Sheet sheet = wb.getSheetAt(sheetIndex);
    this.totalRows = sheet.getPhysicalNumberOfRows();
    if ((this.totalRows >= 1) && (sheet.getRow(0) != null)) {
        this.totalCells = sheet.getRow(0).getLastCellNum(); // 获取最后一个不为空的列是第几个
    }
    for (int r = 0; r < this.totalRows; r++) {
        Row row = sheet.getRow(r);
        if (row != null) {
            List<String> rowLst = Lists.newArrayList();
            for (int c = 0; c < getTotalCells(); c++) {
                Cell cell = row.getCell(c);

                String cellValue = "";
                if (cell != null) {
                    switch (cell.getCellType()) {
                        case 0:
                            if (HSSFDateUtil.isCellDateFormatted(cell)) {
                                Date date = cell.getDateCellValue();

                                cellValue = DateUtils.dateToStr(date,
                                        "yyyy-MM-dd HH:mm:ss");

                            } else {
                                Integer num = (int) cell.getNumericCellValue();
                                cellValue = String.valueOf(num);
                            }
                            break;
                        case 1:
                            cellValue = cell.getStringCellValue().trim();
                            break;
                        case 4:
                            cellValue = String.valueOf(cell.getBooleanCellValue());
                            break;
                        case 2:
                            cellValue = cell.getCellFormula();
                            break;
                        case 3:
                            cellValue = "";
                            break;
                        case 5:
                            cellValue = "非法字符";
                            break;
                        default:
                            cellValue = "未知类型";
                    }
                }
                rowLst.add(cellValue);
            }
            dataLst.add(rowLst);
        }
    }
    return dataLst;
}
 
开发者ID:DreamYa0,项目名称:zeratul,代码行数:56,代码来源:HandleExcel.java


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