本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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;
}