本文整理匯總了Java中org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BLANK屬性的典型用法代碼示例。如果您正苦於以下問題:Java Cell.CELL_TYPE_BLANK屬性的具體用法?Java Cell.CELL_TYPE_BLANK怎麽用?Java Cell.CELL_TYPE_BLANK使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.apache.poi.ss.usermodel.Cell
的用法示例。
在下文中一共展示了Cell.CELL_TYPE_BLANK屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getCharValue
private char getCharValue(Cell cell) {
int vType = getCellType(cell);
switch (vType) {
case Cell.CELL_TYPE_BLANK:
return 0;
case Cell.CELL_TYPE_NUMERIC:
return (char) cell.getNumericCellValue();
case Cell.CELL_TYPE_STRING:
String vStr = cell.getStringCellValue();
if (vStr.length() == 1)
return vStr.charAt(0);
else
throw new IllegalArgumentException("Can't get char from String whose length > 1");
default:
throw new IllegalArgumentException("Can't get char from type " + vType);
}
}
示例2: getNativeValueType
@Override
public ValueType getNativeValueType(int columnIndex) throws ParseException {
Cell cell = getCurrentCell(columnIndex);
final int type = cell.getCellType();
if (type == Cell.CELL_TYPE_BLANK) {
return ValueType.EMPTY;
} else if (type == Cell.CELL_TYPE_STRING) {
return ValueType.STRING;
} else if (type == Cell.CELL_TYPE_NUMERIC) {
if (DateUtil.isCellDateFormatted(cell)) {
return ValueType.DATE;
} else {
return ValueType.NUMBER;
}
} else if (type == Cell.CELL_TYPE_FORMULA) {
if (cell.getCachedFormulaResultType() == Cell.CELL_TYPE_NUMERIC) {
return ValueType.NUMBER;
} else {
return ValueType.STRING;
}
} else {
return ValueType.STRING;
}
}
示例3: getCellValue
public Object getCellValue(Cell cell){
Object value = null;
DecimalFormat df = new DecimalFormat("0"); //格式化number String字符
DecimalFormat df2 = new DecimalFormat("0.00"); //格式化數字
switch (cell.getCellType()) {
case Cell.CELL_TYPE_STRING:
value = cell.getRichStringCellValue().getString();
break;
case Cell.CELL_TYPE_NUMERIC:
if("General".equals(cell.getCellStyle().getDataFormatString())) {
value = df.format(cell.getNumericCellValue());
} else {
value = df2.format(cell.getNumericCellValue());
}
break;
case Cell.CELL_TYPE_BOOLEAN:
value = cell.getBooleanCellValue();
break;
case Cell.CELL_TYPE_BLANK:
value = "";
break;
default:
break;
}
return value;
}
示例4: getNumbericValue
private double getNumbericValue(Cell cell, Class<? extends Number> clazz) {
double vRet;
int vType = getCellType(cell);
switch (vType) {
case Cell.CELL_TYPE_BLANK:
vRet = 0;
break;
case Cell.CELL_TYPE_NUMERIC:
vRet = cell.getNumericCellValue();
break;
case Cell.CELL_TYPE_STRING:
String vStr = cell.getStringCellValue();
vRet = Double.valueOf(vStr);
break;
default:
throw new IllegalArgumentException("Can't get " + clazz.getSimpleName() + " from type " + vType);
}
return vRet;
}
示例5: getStringValue
private String getStringValue(Cell cell) {
int vType = getCellType(cell);
switch (vType) {
case Cell.CELL_TYPE_STRING:
return cell.getStringCellValue();
case Cell.CELL_TYPE_BOOLEAN:
return String.valueOf(cell.getBooleanCellValue());
case Cell.CELL_TYPE_NUMERIC:
double vValue = cell.getNumericCellValue();
if (doubleIsInt(vValue))
return String.valueOf((int) vValue);
return String.valueOf(vValue);
case Cell.CELL_TYPE_BLANK:
return "";
default:
throw new IllegalArgumentException("Can't get String from type " + vType);
}
}
示例6: getEmptyRow
public static int getEmptyRow(Workbook wb, int sheetIndex, String cellRef) {
final Sheet sheet = wb.getSheetAt(sheetIndex);
final CellReference cellReference = new CellReference(cellRef); // һ����A1
boolean flag = false;
for (int i = cellReference.getRow(); i <= sheet.getLastRowNum();) {
final Row r = sheet.getRow(i);
if (r == null) {
// ����ǿ��У���û���κ����ݡ���ʽ����ֱ�Ӱ������µ����������ƶ�
sheet.shiftRows(i + 1, sheet.getLastRowNum(), -1);
continue;
}
flag = false;
for (final Cell c : r) {
if (c.getCellType() != Cell.CELL_TYPE_BLANK) {
flag = true;
break;
}
}
if (flag) {
i++;
continue;
} else {// ����ǿհ��У�������û�����ݣ�������һ����ʽ��
if (i == sheet.getLastRowNum())// ����������һ�У�ֱ�ӽ���һ��remove��
sheet.removeRow(r);
else// �����û�����һ�У�������������һ��
sheet.shiftRows(i + 1, sheet.getLastRowNum(), -1);
}
}
return sheet.getLastRowNum() + 1;
}
示例7: dataFormat
/**
* 對讀取excel的數據進行格式轉換
*
* @param cell
* @return
* @throws Exception
*/
private Object dataFormat(Cell cell) throws Exception {
try {
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_NUMERIC:
return cellTypeNumeric(cell);
case HSSFCell.CELL_TYPE_STRING:
return cell.getStringCellValue();
case Cell.CELL_TYPE_BLANK:
return "";
default:
return cell.getStringCellValue();
}
} catch (Exception e) {
logger.debug("excel數據格式化錯誤!");
throw e;
}
}
示例8: intercepterCellValue
public void intercepterCellValue(Cell cell, CellWrapper cellWrapper, String interceptor) throws Exception {
if (cell == null) {
cellWrapper.setValue(null);
} else {
int cellType = cell.getCellType();
switch (cellType) {
case Cell.CELL_TYPE_BLANK:
cellWrapper.setValue(null);
break;
case Cell.CELL_TYPE_BOOLEAN:
cellWrapper.setValue(Boolean.valueOf(cell.getBooleanCellValue()));
break;
case Cell.CELL_TYPE_ERROR:
cellWrapper.setValue(cell.getErrorCellValue());
break;
case Cell.CELL_TYPE_FORMULA:
cellWrapper.setValue(cell.getCellFormula());
break;
case Cell.CELL_TYPE_NUMERIC:
if (DateUtil.isCellDateFormatted(cell)) {
Date date = cell.getDateCellValue();
cellWrapper.setValue(date);
} else {
cellWrapper.setValue(cell.getNumericCellValue());
}
break;
case Cell.CELL_TYPE_STRING:
cellWrapper.setValue(cell.getStringCellValue());
break;
}
}
logger.debug("before interceptor column number[" + cellWrapper.getColumn() + "] cell value[" + cellWrapper.getValue() + "] cell intercepter[" + interceptor + "]");
this.intercepterCellValue(cellWrapper, interceptor);
logger.debug("after interceptor cell value[" + cellWrapper.getValue() + "]");
}
示例9: isMissing
@Override
public boolean isMissing(int columnIndex) {
Cell cell = getCurrentCell(columnIndex);
try {
boolean missing = cell == null || cell.getCellType() == Cell.CELL_TYPE_BLANK
|| cell.getCellType() == Cell.CELL_TYPE_ERROR || "".equals(cell.getStringCellValue().trim());
return missing;
} catch (IllegalStateException e) {
return false;
}
}
示例10: getValue
/** 從表格之中讀取數據並進行處理
* @param fieldInfo
* @param cell 當前cell
* @return
* @throws Exception
*/
public static Object getValue(ImportFieldInfo fieldInfo, Cell cell) throws Exception{
int size = fieldInfo.getTypeChain().size();
Class<?> type = fieldInfo.getTypeChain().get(size - 1);
String dateFormat = fieldInfo.getDateFormat();
int cellType = cell.getCellType();
Object obj = null ;
switch (cellType) {
case Cell.CELL_TYPE_BLANK:
return null;
case Cell.CELL_TYPE_BOOLEAN:
obj = cell.getBooleanCellValue();
break;
case Cell.CELL_TYPE_STRING:
obj = cell.getStringCellValue();
break;
case Cell.CELL_TYPE_NUMERIC:
if(DateUtil.isCellDateFormatted(cell)){
obj = DateUtil.getJavaDate(cell.getNumericCellValue());
}else if(Number.class.isAssignableFrom(type) || ClassUtils.isBaseNumberType(type)){
//當pojo字段類型是數字型時以數字形式獲取
obj = cell.getNumericCellValue();
}else{
//其他類型都以string獲取
obj = DATA_FORMATTER.formatCellValue(cell);
}
break;
case Cell.CELL_TYPE_ERROR:
return null;
}
if(fieldInfo.getImportProcessor() != null){
obj = fieldInfo.getImportProcessor().process(obj);
}
obj = ConvertUtils.convertIfNeccesary(obj, type, dateFormat);
return obj;
}
示例11: firstEmptyCellPosition
private int firstEmptyCellPosition(final Row cells) {
int columnCount = 0;
for (Cell cell : cells) {
if (cell.getCellType() == Cell.CELL_TYPE_BLANK) {
break;
}
columnCount++;
}
return columnCount;
}
示例12: getValue
@SuppressWarnings("deprecation")
private Object getValue(Cell raw, String fieldType) throws CellParsingException {
switch (raw.getCellType()) {
case Cell.CELL_TYPE_BOOLEAN:
return raw.getBooleanCellValue();
case Cell.CELL_TYPE_STRING: {
String s = raw.getStringCellValue();
String boolString = s.toLowerCase();
if (boolString.equals("yes"))
return true;
if (boolString.equals("no"))
return false;
return s;
}
case Cell.CELL_TYPE_NUMERIC:
if (DateUtil.isCellDateFormatted(raw)) {
Date date = raw.getDateCellValue();
return LocalDate.of(date.getYear() + 1900, date.getMonth() + 1, date.getDate());
}
return (int) raw.getNumericCellValue();
// formula parsing doesnot work
// can be done using FormulaEvaluater
case Cell.CELL_TYPE_FORMULA:
return true;
case Cell.CELL_TYPE_BLANK: {
return getInstance(fieldType);
}
}
return null;
}
示例13: isEmpty
private boolean isEmpty(final Row row) {
Cell firstCell = row.getCell(0);
boolean rowIsEmpty = (firstCell == null)
|| (firstCell.getCellType() == Cell.CELL_TYPE_BLANK);
return rowIsEmpty;
}
示例14: isNullCell
private static boolean isNullCell(Cell cell) {
return cell == null || Cell.CELL_TYPE_BLANK == cell.getCellType();
}
示例15: processSpreadsheetUpload
private void processSpreadsheetUpload(Workbook wb, List<Map<QName,String>> users)
throws IOException
{
if (wb.getNumberOfSheets() > 1)
{
logger.info("Uploaded Excel file has " + wb.getNumberOfSheets() +
" sheets, ignoring all except the first one");
}
int firstRow = 0;
Sheet s = wb.getSheetAt(0);
DataFormatter df = new DataFormatter();
String[][] data = new String[s.getLastRowNum()+1][];
// If there is a heading freezepane row, skip it
PaneInformation pane = s.getPaneInformation();
if (pane != null && pane.isFreezePane() && pane.getHorizontalSplitTopRow() > 0)
{
firstRow = pane.getHorizontalSplitTopRow();
logger.debug("Skipping excel freeze header of " + firstRow + " rows");
}
// Process each row in turn, getting columns up to our limit
for (int row=firstRow; row <= s.getLastRowNum(); row++)
{
Row r = s.getRow(row);
if (r != null)
{
String[] d = new String[COLUMNS.length];
for (int cn=0; cn<COLUMNS.length; cn++)
{
Cell cell = r.getCell(cn);
if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK)
{
d[cn] = df.formatCellValue(cell);
}
}
data[row] = d;
}
}
// Handle the contents
processSpreadsheetUpload(data, users);
}