本文整理汇总了Java中org.apache.poi.hssf.usermodel.HSSFCell.CELL_TYPE_FORMULA属性的典型用法代码示例。如果您正苦于以下问题:Java HSSFCell.CELL_TYPE_FORMULA属性的具体用法?Java HSSFCell.CELL_TYPE_FORMULA怎么用?Java HSSFCell.CELL_TYPE_FORMULA使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.poi.hssf.usermodel.HSSFCell
的用法示例。
在下文中一共展示了HSSFCell.CELL_TYPE_FORMULA属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCellValue
private String getCellValue(HSSFCell cell){
if(cell == null) return "";
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING: return cell.getStringCellValue();
case HSSFCell.CELL_TYPE_BOOLEAN : return Boolean.toString(cell.getBooleanCellValue());
case HSSFCell.CELL_TYPE_NUMERIC :
if(HSSFDateUtil.isCellDateFormatted(cell))
return DateUtils.formatDateTime("yyyyMMdd", HSSFDateUtil.getJavaDate(cell.getNumericCellValue()));
else
return new BigDecimal(cell.getNumericCellValue()).toPlainString();
case HSSFCell.CELL_TYPE_FORMULA : return "";
case HSSFCell.CELL_TYPE_BLANK : return "";
default:return "";
}
}
示例2: getValueFromCell
/**
* <b>描述:</b> 从单元格中获取到的数据
* @param cell 单元格对应的HSSFCell对象
* @return Object 从单元格中获取到的数据
*/
private Object getValueFromCell(HSSFCell cell){
if(cell==null)return "";
switch(cell.getCellType()){
case HSSFCell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue();
case HSSFCell.CELL_TYPE_NUMERIC:
return cell.getNumericCellValue();
case HSSFCell.CELL_TYPE_FORMULA:
return cell.getCellFormula();
case HSSFCell.CELL_TYPE_STRING:
return cell.getRichStringCellValue().toString();
default:
return cell.getRichStringCellValue().toString();
}
}
示例3: getCellData
/**
* Get cell value based on the excel column data type
*
* @param myCell
* @return
*/
private static String getCellData(HSSFCell myCell) throws Exception {
String cellData = "";
if (myCell == null) {
cellData += CVS_SEPERATOR_CHAR;;
} else {
switch (myCell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
case HSSFCell.CELL_TYPE_BOOLEAN:
cellData += myCell.getRichStringCellValue() + CVS_SEPERATOR_CHAR;
break;
case HSSFCell.CELL_TYPE_NUMERIC:
cellData += getNumericValue(myCell);
break;
case HSSFCell.CELL_TYPE_FORMULA:
cellData += getFormulaValue(myCell);
default:
cellData += CVS_SEPERATOR_CHAR;
;
}
}
return cellData;
}
示例4: getCellStringValue
public static String getCellStringValue(HSSFCell cell) {
String cellValue = "";
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
cellValue = cell.getStringCellValue();
if (cellValue.trim().equals("") || cellValue.trim().length() <= 0) {
cellValue = " ";
}
break;
case HSSFCell.CELL_TYPE_NUMERIC:
// cellValue = String.valueOf(cell.getNumericCellValue());
DecimalFormat formatter = new DecimalFormat("######");
cellValue = formatter.format(cell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_FORMULA:
cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
cellValue = String.valueOf(cell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_BLANK:
cellValue = " ";
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
break;
case HSSFCell.CELL_TYPE_ERROR:
break;
default:
break;
}
return cellValue;
}
示例5: copyCell
/**
* @param oldCell
* @param newCell
* @param styleMap
*/
public static void copyCell(HSSFCell oldCell, HSSFCell newCell, Map<Integer, HSSFCellStyle> styleMap) {
if (styleMap != null) {
if (oldCell.getSheet().getWorkbook() == newCell.getSheet().getWorkbook()) {
newCell.setCellStyle(oldCell.getCellStyle());
} else {
int stHashCode = oldCell.getCellStyle().hashCode();
HSSFCellStyle newCellStyle = styleMap.get(stHashCode);
if (newCellStyle == null) {
newCellStyle = newCell.getSheet().getWorkbook().createCellStyle();
newCellStyle.cloneStyleFrom(oldCell.getCellStyle());
styleMap.put(stHashCode, newCellStyle);
}
newCell.setCellStyle(newCellStyle);
}
}
switch (oldCell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
newCell.setCellValue(oldCell.getStringCellValue());
break;
case HSSFCell.CELL_TYPE_NUMERIC:
newCell.setCellValue(oldCell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_BLANK:
newCell.setCellType(HSSFCell.CELL_TYPE_BLANK);
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
newCell.setCellValue(oldCell.getBooleanCellValue());
break;
case HSSFCell.CELL_TYPE_ERROR:
newCell.setCellErrorValue(oldCell.getErrorCellValue());
break;
case HSSFCell.CELL_TYPE_FORMULA:
newCell.setCellFormula(oldCell.getCellFormula());
break;
default:
break;
}
}
示例6: getCellFormatValue
/**
* 根据HSSFCell类型设置数据
*
* @param cell
* @return
*/
private String getCellFormatValue(Cell cell) {
String cellvalue = "";
if (cell != null) {
// 判断当前Cell的Type
switch (cell.getCellType()) {
// 如果当前Cell的Type为NUMERIC
case HSSFCell.CELL_TYPE_NUMERIC:
case HSSFCell.CELL_TYPE_FORMULA: {
// 判断当前的cell是否为Date
if (HSSFDateUtil.isCellDateFormatted(cell)) {
// 如果是Date类型则,转化为Data格式
// 方法1:这样子的data格式是带时分秒的:2011-10-12 0:00:00
// cellvalue = cell.getDateCellValue().toLocaleString();
// 方法2:这样子的data格式是不带带时分秒的:2011-10-12
Date date = cell.getDateCellValue();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
cellvalue = sdf.format(date);
}
// 如果是纯数字
else {
// 取得当前Cell的数值
cellvalue = String.valueOf(cell.getNumericCellValue());
}
break;
}
// 如果当前Cell的Type为STRIN
case HSSFCell.CELL_TYPE_STRING:
// 取得当前的Cell字符串
cellvalue = cell.getRichStringCellValue().getString();
break;
// 默认的Cell值
default:
cellvalue = " ";
}
} else {
cellvalue = "";
}
return cellvalue;
}
示例7: getCellData
@SuppressWarnings("null")
public static String getCellData(String reqValue, HSSFSheet reqSheet,
int rowIndex, HashMap<String, Object> inputHashTable)
throws IOException {
HSSFCell reqCell = null;
Object actualvalue = null;
String req = "";
DataFormatter fmt = new DataFormatter();
if (inputHashTable.isEmpty() == true) {
inputHashTable = getValueFromHashMap(reqSheet);
}
HSSFRow rowActual = reqSheet.getRow(rowIndex);
if (inputHashTable.get(reqValue) == null) {
report.setStrMessage("Column " + reqValue
+ " not Found. Please Check input Sheet");
pauseFun("Column " + reqValue
+ " not Found. Please Check input Sheet");
} else {
actualvalue = inputHashTable.get(reqValue);// rowHeader.getCell(colIndex).toString();
if (actualvalue != null) {
int colIndex = Integer.parseInt(actualvalue.toString());
reqCell = rowActual.getCell(colIndex);
if (reqCell == null) {
System.out.println(reqValue + " is Null");
} else {
int type = reqCell.getCellType();
switch (type) {
case HSSFCell.CELL_TYPE_BLANK:
req = "";
break;
case HSSFCell.CELL_TYPE_NUMERIC:
req = fmt.formatCellValue(reqCell);
break;
case HSSFCell.CELL_TYPE_STRING:
req = reqCell.getStringCellValue();
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
req = Boolean.toString(reqCell.getBooleanCellValue());
break;
case HSSFCell.CELL_TYPE_ERROR:
req = "error";
break;
case HSSFCell.CELL_TYPE_FORMULA:
req = reqCell.getCellFormula();
break;
}
}
}
else {
req = reqCell.getStringCellValue();
System.out.println("null");
}
}
return req;
}
示例8: getCellString
private Object getCellString(HSSFCell cell) {
// TODO Auto-generated method stub
Object result = null;
if (cell != null) {
// 单元格类型:Numeric:0,String:1,Formula:2,Blank:3,Boolean:4,Error:5
int cellType = cell.getCellType();
switch (cellType) {
case HSSFCell.CELL_TYPE_STRING:
result = cell.getRichStringCellValue().getString();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
result = cell.getNumericCellValue();
break;
case HSSFCell.CELL_TYPE_FORMULA:
result = cell.getNumericCellValue();
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
result = cell.getBooleanCellValue();
break;
case HSSFCell.CELL_TYPE_BLANK:
result = null;
break;
case HSSFCell.CELL_TYPE_ERROR:
result = null;
break;
default:
System.out.println("枚举了所有类型");
break;
}
}
return result;
}
示例9: getHSSFCellValue
public String getHSSFCellValue(HSSFCell cell) {
String value = "";
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_NUMERIC:
if (HSSFDateUtil.isCellDateFormatted(cell)) {
value = HSSFDateUtil.getJavaDate(cell.getNumericCellValue())
.toString();
} else {
value = String.valueOf(cell.getNumericCellValue());
}
break;
case HSSFCell.CELL_TYPE_STRING:
value = cell.getRichStringCellValue().toString();
break;
case HSSFCell.CELL_TYPE_FORMULA:
value = String.valueOf(cell.getNumericCellValue());
if (value.equals("NaN")) {
value = cell.getRichStringCellValue().toString();
}
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
value = "" + cell.getBooleanCellValue();
break;
case HSSFCell.CELL_TYPE_BLANK:
value = "";
break;
case HSSFCell.CELL_TYPE_ERROR:
value = "";
break;
default:
value = cell.getRichStringCellValue().toString();
}
return value;
}
示例10: getCellValue
public static String getCellValue(HSSFCell cell) {
String value = "";
if (cell==null)
return "";
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
value = cell.getStringCellValue();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
double tp=Double.valueOf(cell.getNumericCellValue());
value=String.format("%.2f", tp);
break;
case HSSFCell.CELL_TYPE_FORMULA:
value = cell.getCellFormula();
break;
case HSSFCell.CELL_TYPE_ERROR:
value = String.valueOf(cell.getErrorCellValue());
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
value = String.valueOf(cell.getBooleanCellValue());
break;
case HSSFCell.CELL_TYPE_BLANK:
value = "";
break;
default:
break;
}
return value;
}
示例11: getCellValue2
public static String getCellValue2(HSSFCell cell) {
String value = "";
if (cell==null)
return "";
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
value = cell.getStringCellValue();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
double tp=Double.valueOf(cell.getNumericCellValue());
value=String.format("%.0f", tp);
break;
case HSSFCell.CELL_TYPE_FORMULA:
value = cell.getCellFormula();
break;
case HSSFCell.CELL_TYPE_ERROR:
value = String.valueOf(cell.getErrorCellValue());
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
value = String.valueOf(cell.getBooleanCellValue());
break;
case HSSFCell.CELL_TYPE_BLANK:
value = "";
break;
default:
break;
}
return value;
}
示例12: extractRowData
private String[] extractRowData(Row row) {
if (row == null || row.getLastCellNum() == -1) {
return null;
}
String[] data = new String[row.getLastCellNum()];
Cell cell;
for (int i = 0; i < data.length; i++) {
cell = row.getCell(i);
if (cell == null) {
data[i] = "";
continue;
}
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
data[i] = cell.getRichStringCellValue().getString();
break;
case HSSFCell.CELL_TYPE_BLANK:
data[i] = "";
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
data[i] = String.valueOf(cell.getBooleanCellValue());
break;
case HSSFCell.CELL_TYPE_FORMULA:
data[i] = "{formula}";
break;
case HSSFCell.CELL_TYPE_NUMERIC:
data[i] = processNumericValue(cell.getNumericCellValue());
break;
}
}
return data;
}
示例13: copyCell
public static void copyCell(HSSFCell oldCell, HSSFCell newCell, Map<Integer, HSSFCellStyle> styleMap) {
if(styleMap != null) {
if(oldCell.getSheet().getWorkbook() == newCell.getSheet().getWorkbook()){
newCell.setCellStyle(oldCell.getCellStyle());
} else{
int stHashCode = oldCell.getCellStyle().hashCode();
HSSFCellStyle newCellStyle = styleMap.get(stHashCode);
if(newCellStyle == null){
newCellStyle = newCell.getSheet().getWorkbook().createCellStyle();
newCellStyle.cloneStyleFrom(oldCell.getCellStyle());
styleMap.put(stHashCode, newCellStyle);
}
newCell.setCellStyle(newCellStyle);
}
}
switch(oldCell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
newCell.setCellValue(oldCell.getStringCellValue());
break;
case HSSFCell.CELL_TYPE_NUMERIC:
newCell.setCellValue(oldCell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_BLANK:
newCell.setCellType(HSSFCell.CELL_TYPE_BLANK);
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
newCell.setCellValue(oldCell.getBooleanCellValue());
break;
case HSSFCell.CELL_TYPE_ERROR:
newCell.setCellErrorValue(oldCell.getErrorCellValue());
break;
case HSSFCell.CELL_TYPE_FORMULA:
newCell.setCellFormula(oldCell.getCellFormula());
break;
default:
break;
}
}
示例14: copyRow
public static void copyRow(HSSFSheet oldSheet, HSSFSheet newSheet,
int oldRowNum, int newRowNum) {
HSSFRow oldRow = oldSheet.getRow(oldRowNum);
HSSFRow newRow = newSheet.createRow(newRowNum);
if (oldRow == null) {
return;
}
newRow.setHeight(oldRow.getHeight());
if (oldRow.getFirstCellNum() == -1) {
return;
}
for (int colNum = oldRow.getFirstCellNum(); colNum <= oldRow
.getLastCellNum(); colNum++) {
HSSFCell oldCell = oldRow.getCell(colNum);
HSSFCell newCell = newRow.createCell(colNum);
if (oldCell != null) {
HSSFCellStyle style = oldCell.getCellStyle();
newCell.setCellStyle(style);
int cellType = oldCell.getCellType();
newCell.setCellType(cellType);
if (cellType == HSSFCell.CELL_TYPE_BOOLEAN) {
newCell.setCellValue(oldCell.getBooleanCellValue());
} else if (cellType == HSSFCell.CELL_TYPE_FORMULA) {
newCell.setCellFormula(oldCell.getCellFormula());
} else if (cellType == HSSFCell.CELL_TYPE_NUMERIC) {
newCell.setCellValue(oldCell.getNumericCellValue());
} else if (cellType == HSSFCell.CELL_TYPE_STRING) {
newCell.setCellValue(oldCell.getRichStringCellValue());
}
}
}
POIUtils.copyMergedRegion(newSheet,
getMergedRegionList(oldSheet, oldRowNum), newRowNum);
}
示例15: getValue
public Object getValue(int row, String column) throws DataSetException {
if (logger.isDebugEnabled())
logger.debug("getValue(row={}, columnName={}) - start", Integer.toString(row), column);
assertValidRowIndex(row);
int columnIndex = getColumnIndex(column);
HSSFCell cell = _sheet.getRow(row + 1).getCell(columnIndex);
if (cell == null) {
return null;
}
int type = cell.getCellType();
switch (type) {
case HSSFCell.CELL_TYPE_NUMERIC:
HSSFCellStyle style = cell.getCellStyle();
if (HSSFDateUtil.isCellDateFormatted(cell)) {
return getDateValue(cell);
} else if (XlsDataSetWriter.DATE_FORMAT_AS_NUMBER_DBUNIT.equals(style.getDataFormatString())) {
// The special dbunit date format
return getDateValueFromJavaNumber(cell);
} else {
return getNumericValue(cell);
}
case HSSFCell.CELL_TYPE_STRING:
return cell.getRichStringCellValue().getString();
case HSSFCell.CELL_TYPE_FORMULA:
throw new DataTypeException("Formula not supported at row=" +
row + ", column=" + column);
case HSSFCell.CELL_TYPE_BLANK:
return null;
case HSSFCell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue() ? Boolean.TRUE : Boolean.FALSE;
case HSSFCell.CELL_TYPE_ERROR:
throw new DataTypeException("Error at row=" + row +
", column=" + column);
default:
throw new DataTypeException("Unsupported type at row=" + row +
", column=" + column);
}
}