本文整理匯總了Java中org.apache.poi.xssf.usermodel.XSSFCell.CELL_TYPE_FORMULA屬性的典型用法代碼示例。如果您正苦於以下問題:Java XSSFCell.CELL_TYPE_FORMULA屬性的具體用法?Java XSSFCell.CELL_TYPE_FORMULA怎麽用?Java XSSFCell.CELL_TYPE_FORMULA使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.apache.poi.xssf.usermodel.XSSFCell
的用法示例。
在下文中一共展示了XSSFCell.CELL_TYPE_FORMULA屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updateCellValue
public void updateCellValue(String cellPosition, String value) throws Exception {
String sheetNumTxt = cellPosition.indexOf("[")>-1 ? cellPosition.substring(cellPosition.indexOf("[")) : null;
if(sheetNumTxt != null) {
this.sheetNum = new Integer(sheetNumTxt.substring(0,sheetNumTxt.length()-1));
cellPosition = cellPosition.substring(cellPosition.indexOf("["));
} else {
this.sheetNum = 0;
}
worksheet = workbook.getSheetAt(this.sheetNum);
CellReference c = new CellReference(cellPosition);
XSSFCell cell = worksheet.getRow(c.getRow()).getCell(c.getCol());
if(cell == null) throw new Exception("Invalid cell reference:" + cellPosition);
if(value == null) {
cell.setCellType(XSSFCell.CELL_TYPE_BLANK);
} else if(cell.getCellType()==XSSFCell.CELL_TYPE_FORMULA) {
this.setCellFormula(cell, value);
} else {
cell.setCellValue(value);
}
}
示例2: getCellTypeName
/**
* 獲取單元格類型名稱
*
* @param cell
* @return
*
*/
public static String getCellTypeName(XSSFCell cell) {
if (cell == null) {
return "null";
}
switch (cell.getCellType()) {
case XSSFCell.CELL_TYPE_BLANK: return "CELL_TYPE_BLANK";
case XSSFCell.CELL_TYPE_BOOLEAN: return "CELL_TYPE_BOOLEAN";
case XSSFCell.CELL_TYPE_ERROR: return "CELL_TYPE_ERROR";
case XSSFCell.CELL_TYPE_FORMULA: return "CELL_TYPE_FORMULA";
case XSSFCell.CELL_TYPE_NUMERIC: return "CELL_TYPE_NUMERIC";
case XSSFCell.CELL_TYPE_STRING: return "CELL_TYPE_STRING";
default: return "unknown";
}
}
示例3: cellValues2String
/**
* Get the value of the excel-cell as String.
*
* @param workbook
* workbook (excel) for evaluating cell formulas
* @param cell
* cell (excel)
*
* @return the value of the excel-cell as String
*/
static String cellValues2String(XSSFWorkbook workbook, XSSFCell cell) {
if (cell == null) {
return null;
}
switch (cell.getCellType()) {
case XSSFCell.CELL_TYPE_NUMERIC:
if (HSSFDateUtil.isCellDateFormatted(cell)) {
return new SimpleDateFormat(JExUnitConfig.getStringProperty(JExUnitConfig.ConfigKey.DATE_PATTERN))
.format(cell.getDateCellValue());
} else {
return String.valueOf(cell.getNumericCellValue());
}
case XSSFCell.CELL_TYPE_STRING:
return cell.getStringCellValue();
case XSSFCell.CELL_TYPE_FORMULA:
return evaluateCellFormula(workbook, cell);
case XSSFCell.CELL_TYPE_BLANK:
return cell.getStringCellValue();
case XSSFCell.CELL_TYPE_BOOLEAN:
return String.valueOf(cell.getBooleanCellValue());
case XSSFCell.CELL_TYPE_ERROR:
return String.valueOf(cell.getErrorCellValue());
}
return null;
}
示例4: copyCell
/**
* @param oldCell
* @param newCell
* @param styleMap
*/
public static void copyCell(XSSFCell oldCell, XSSFCell newCell, Map<Integer, XSSFCellStyle> styleMap) {
if (styleMap != null) {
if (oldCell.getSheet().getWorkbook() == newCell.getSheet().getWorkbook()) {
newCell.setCellStyle(oldCell.getCellStyle());
} else {
int stHashCode = oldCell.getCellStyle().hashCode();
XSSFCellStyle 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 XSSFCell.CELL_TYPE_STRING:
newCell.setCellValue(oldCell.getStringCellValue());
break;
case XSSFCell.CELL_TYPE_NUMERIC:
newCell.setCellValue(oldCell.getNumericCellValue());
break;
case XSSFCell.CELL_TYPE_BLANK:
newCell.setCellType(XSSFCell.CELL_TYPE_BLANK);
break;
case XSSFCell.CELL_TYPE_BOOLEAN:
newCell.setCellValue(oldCell.getBooleanCellValue());
break;
case XSSFCell.CELL_TYPE_ERROR:
newCell.setCellErrorValue(oldCell.getErrorCellValue());
break;
case XSSFCell.CELL_TYPE_FORMULA:
newCell.setCellFormula(oldCell.getCellFormula());
break;
default:
break;
}
}
示例5: copyCell
/**
* Copy a cell to another cell
*
* @param oldCell cell to be copied
* @param newCell cell to be created
* @param styleMap style map
*/
public static void copyCell(XSSFCell oldCell, XSSFCell newCell, Map<Integer, CellStyle> styleMap) {
if (styleMap != null) {
if (oldCell.getSheet().getWorkbook() == newCell.getSheet().getWorkbook()) {
newCell.setCellStyle(oldCell.getCellStyle());
} else {
int stHashCode = oldCell.getCellStyle().hashCode();
CellStyle 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 XSSFCell.CELL_TYPE_STRING:
newCell.setCellValue(oldCell.getStringCellValue());
break;
case XSSFCell.CELL_TYPE_NUMERIC:
newCell.setCellValue(oldCell.getNumericCellValue());
break;
case XSSFCell.CELL_TYPE_BLANK:
newCell.setCellType(XSSFCell.CELL_TYPE_BLANK);
break;
case XSSFCell.CELL_TYPE_BOOLEAN:
newCell.setCellValue(oldCell.getBooleanCellValue());
break;
case XSSFCell.CELL_TYPE_ERROR:
newCell.setCellErrorValue(oldCell.getErrorCellValue());
break;
case XSSFCell.CELL_TYPE_FORMULA:
newCell.setCellFormula(oldCell.getCellFormula());
break;
default:
break;
}
}
示例6: shiftRange
private void shiftRange(int numRowsDown, int rowStart, int rowEnd, int colStart, int colEnd) throws Exception {
// loop through from bottom row up to either SHIFT the whole row, or copy necessary columns, insert new row below, insert the data from the cell and then delete all style and format from the original cell
for(int j=rowEnd;j>rowStart;j--) {
XSSFRow row = worksheet.getRow(j);
XSSFRow newRow = worksheet.getRow(j+numRowsDown);
if(row == null && newRow == null)
continue;
else if (row == null) {
worksheet.removeRow(newRow);
continue;
}
if(newRow == null) {
newRow = worksheet.createRow(j+numRowsDown);
}
// newRow = worksheet.getRow(j+numRowsDown);
//if(row ==null) continue;
for(int k=colStart;k<=colEnd;k++) {
XSSFCell cell = row.getCell(k);
if(cell != null) {
XSSFCell newCell = newRow.getCell(k)==null ? newRow.createCell(k) : newRow.getCell(k);
if(cell==null) continue;
if(cell.getCellType() == XSSFCell.CELL_TYPE_FORMULA) {
String calc = cell.getCellFormula();
newCell.setCellStyle(cell.getCellStyle());
cell.setCellType(XSSFCell.CELL_TYPE_BLANK);
this.setCellFormula(newCell, calc);
} else if(cell.getCellType()==XSSFCell.CELL_TYPE_BLANK) {
newCell.setCellType(XSSFCell.CELL_TYPE_BLANK);
} else {
newCell.copyCellFrom(cell, new CellCopyPolicy());
newCell.setCellStyle(cell.getCellStyle());
}
}
}
}
}
示例7: getExcelReader
public static List<Map<String, String>> getExcelReader() {
String[] colName = { "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" };
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
try {
FileInputStream fis = new FileInputStream("c:\\wdmFx\\db\\webtoonList1.xlsx");
XSSFWorkbook workbook = new XSSFWorkbook(fis);
// 시트 수 (첫번째에만 존재하므로 0을 준다)
// 만약 각 시트를 읽기위해서는 FOR문을 한번더 돌려준다
XSSFSheet sheet = workbook.getSheetAt(0);
int rows = sheet.getPhysicalNumberOfRows();
Map<String, String> map = null;
for (int i = 0; i < rows; i++) {
if (i != 0) {
XSSFRow row = sheet.getRow(i); // 행을 읽는다
String value = "";
// 셀의 갯수를 실제 필드갯수로 지정.
int cells = colName.length;
map = new LinkedHashMap<String, String>();
for (int j = 0; j < cells; j++) {
XSSFCell cell = row.getCell(j); // 셀값을 읽는다
if (cell != null) {
switch (cell.getCellType()) {
case XSSFCell.CELL_TYPE_FORMULA:
if (!"".equals(cell.toString())) {
value = cell.getCellFormula();
}
break;
case XSSFCell.CELL_TYPE_NUMERIC:
value = cell.getRawValue();
break;
case XSSFCell.CELL_TYPE_STRING:
value = cell.getStringCellValue();
break;
case XSSFCell.CELL_TYPE_BLANK:
value = "";
break;
case XSSFCell.CELL_TYPE_ERROR:
value = cell.getErrorCellValue() + "";
break;
default:
break;
}
map.put(colName[j], value);
}
} // end for
if (map.get(colName[0]) != null)
list.add(map);
} // end for
}
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
示例8: getValue
/**
* <p>
* xlsx 엑셀의 셀값을 String 타입으로 변환하여 리턴한다.
* </p>
* @param cell
* <code>XSSFCell</code>
* @return 결과 값
*/
public static String getValue(XSSFCell cell) {
String result = "";
if (null == cell || cell.equals(null))
return "";
if (cell.getCellType() == XSSFCell.CELL_TYPE_BOOLEAN) {
log.debug("### XSSFCell.CELL_TYPE_BOOLEAN : "
+ XSSFCell.CELL_TYPE_BOOLEAN);
result = String.valueOf(cell.getBooleanCellValue());
} else if (cell.getCellType() == XSSFCell.CELL_TYPE_ERROR) {
log.debug("### XSSFCell.CELL_TYPE_ERROR : "
+ XSSFCell.CELL_TYPE_ERROR);
// byte errorValue =
// cell.getErrorCellValue();
} else if (cell.getCellType() == XSSFCell.CELL_TYPE_FORMULA) {
log.debug("### XSSFCell.CELL_TYPE_FORMULA : "
+ XSSFCell.CELL_TYPE_FORMULA);
String stringValue = cell.getRichStringCellValue().getString();
String longValue = doubleToString(cell.getNumericCellValue());
result =
EgovStringUtil.isNumeric(longValue) ? longValue : stringValue;
} else if (cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) {
log.debug("### XSSFCell.CELL_TYPE_NUMERIC : "
+ XSSFCell.CELL_TYPE_NUMERIC);
result =
HSSFDateUtil.isCellDateFormatted(cell)
? EgovDateUtil.toString(cell.getDateCellValue(),
"yyyy/MM/dd", null) : doubleToString(cell
.getNumericCellValue());
} else if (cell.getCellType() == XSSFCell.CELL_TYPE_STRING) {
log.debug("### XSSFCell.CELL_TYPE_STRING : "
+ XSSFCell.CELL_TYPE_STRING);
result = cell.getRichStringCellValue().getString();
} else if (cell.getCellType() == XSSFCell.CELL_TYPE_BLANK) {
log.debug("### XSSFCell.CELL_TYPE_BLANK : "
+ XSSFCell.CELL_TYPE_BLANK);
}
return result;
}