當前位置: 首頁>>代碼示例>>Java>>正文


Java Cell.CELL_TYPE_STRING屬性代碼示例

本文整理匯總了Java中org.apache.poi.ss.usermodel.Cell.CELL_TYPE_STRING屬性的典型用法代碼示例。如果您正苦於以下問題:Java Cell.CELL_TYPE_STRING屬性的具體用法?Java Cell.CELL_TYPE_STRING怎麽用?Java Cell.CELL_TYPE_STRING使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.apache.poi.ss.usermodel.Cell的用法示例。


在下文中一共展示了Cell.CELL_TYPE_STRING屬性的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);
	}
}
 
開發者ID:xinufo,項目名稱:teemo,代碼行數:17,代碼來源:RowExcelImpl.java

示例2: isBlankRow

/**
 * 判斷空行
 */
private static boolean isBlankRow(Row row) {
    if (row == null) {
        return true;
    }
    boolean result = true;
    Iterator<Cell> cells = row.cellIterator();
    String value = "";
    while (cells.hasNext()) {
        Cell cell = cells.next();
        int cellType = cell.getCellType();
        switch (cellType) {
            case Cell.CELL_TYPE_NUMERIC:
                value = String.valueOf(cell.getNumericCellValue());
                break;
            case Cell.CELL_TYPE_STRING:
                value = cell.getStringCellValue();
                break;
            case Cell.CELL_TYPE_BOOLEAN:
                value = String.valueOf(cell.getBooleanCellValue());
                break;
            case Cell.CELL_TYPE_FORMULA:
                value = String.valueOf(cell.getCellFormula());
                break;
        }
        if (StringUtils.isNotBlank(value)) {
            result = false;
            break;
        }
    }

    return result;
}
 
開發者ID:goribun,項目名稱:excel-rw-annotation,代碼行數:35,代碼來源:BaseReadUtil.java

示例3: main

public static void main(String[] args) {
        //Create Workbook instance holding reference to .xlsx file
        try (FileInputStream file = new FileInputStream(
                new File("Sample.xlsx"))) {
            //Create Workbook instance holding reference to .xlsx file
            XSSFWorkbook workbook = new XSSFWorkbook(file);

            //Get first/desired sheet from the workbook
            XSSFSheet sheet = workbook.getSheetAt(0);

            //Iterate through each rows one by one
//            Iterator<Row> rowIterator = sheet.iterator();
            for(Row row : sheet) {
                for (Cell cell : row) {
                    //Check the cell type and format accordingly
                    switch (cell.getCellType()) {
                        case Cell.CELL_TYPE_NUMERIC:
                            out.print(cell.getNumericCellValue() + "\t");
                            break;
                        case Cell.CELL_TYPE_STRING:
                            out.print(cell.getStringCellValue() + "\t");
                            break;
                    }
                }
                out.println();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
開發者ID:PacktPublishing,項目名稱:Java-for-Data-Science,代碼行數:30,代碼來源:ReadExcelExample.java

示例4: objectFrom

private Object objectFrom(final HSSFWorkbook workbook, final Cell cell) {
    Object cellValue = null;
    if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
        cellValue = cell.getRichStringCellValue().getString();
    } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
        cellValue = getNumericCellValue(cell);
    } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
        cellValue = cell.getBooleanCellValue();
    } else if (cell.getCellType()  == Cell.CELL_TYPE_FORMULA) {
        cellValue = evaluateCellFormula(workbook, cell);
    }
    return cellValue;

}
 
開發者ID:cyber-coders-j2017a,項目名稱:modern.core.java.repo,代碼行數:14,代碼來源:ExcelXlsReaderParameter.java

示例5: 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;
}
 
開發者ID:xinufo,項目名稱:teemo,代碼行數:19,代碼來源:RowExcelImpl.java

示例6: geByte

public static Byte geByte(Cell cell) {
    if (isNullCell(cell)) {
        return null;
    }
    if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) {
        return (byte) cell.getNumericCellValue();
    }
    if (Cell.CELL_TYPE_STRING == cell.getCellType()) {
        String value = cell.getStringCellValue();
        if(StringUtils.isNotEmpty(value)){
            Byte.valueOf(cell.getStringCellValue());
        }else{
            return null;
        }
    }
    throw new RuntimeException("can not convertWithConstructor cell value to Integer!");
}
 
開發者ID:dengxiangjun,項目名稱:OfficeAutomation,代碼行數:17,代碼來源:CellConvert.java

示例7: 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() + "]");

}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:36,代碼來源:AbstractExcelParser.java

示例8: getDate

public static Date getDate(Cell cell, String format) throws ParseException {
    if (isNullCell(cell)) {
        return null;
    }
    switch (cell.getCellType()) {
        case Cell.CELL_TYPE_NUMERIC:// 數字類型
            return getCellDate(cell);
        case Cell.CELL_TYPE_STRING:
            if(StringUtils.isNotEmpty(cell.getStringCellValue())){
                return DateUtils.parseDate(cell.getStringCellValue(), format);
            }else{
                return null;
            }
        default:
            throw new RuntimeException("can not convertWithConstructor cell value to Date!");
    }
}
 
開發者ID:dengxiangjun,項目名稱:OfficeAutomation,代碼行數:17,代碼來源:CellConvert.java

示例9: 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;
}
 
開發者ID:long47964,項目名稱:excel-utils,代碼行數:45,代碼來源:ExcelImportUtil.java

示例10: getCellValue

/**
 * 獲取單元格值
 *
 * @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,代碼行數:41,代碼來源:ImportExcel.java

示例11: getLong

public static Long getLong(Cell cell) {
    if (isNullCell(cell)) {
        return null;
    }
    if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) {
        return (long) cell.getNumericCellValue();
    }
    if (Cell.CELL_TYPE_STRING == cell.getCellType()) {
        return Longs.tryParse(cell.getStringCellValue());
    }
    throw new RuntimeException("can not convertWithConstructor cell value to Long!");
}
 
開發者ID:dengxiangjun,項目名稱:OfficeAutomation,代碼行數:12,代碼來源:CellConvert.java

示例12: getCellData_XLS

/** To get cell data from Excel-XLS */
public static Object getCellData_XLS(int RowNum, int ColNum) throws Exception
{
	Object CellData = null;
	try
	{
		xlsCell = xlsWorkSheet.getRow(RowNum).getCell(ColNum);
		if(xlsCell.getCellType() == Cell.CELL_TYPE_STRING )
		{
			String stringCellData = xlsCell.getStringCellValue();
			CellData = stringCellData;
		}
		/*		else if(xlsCell.getCellType() == Cell.CELL_TYPE_NUMERIC)
		{
			double numericCellData =  xlsCell.getNumericCellValue();
			CellData = numericCellData;
		}
		else if(xlsCell.getCellType() == Cell.CELL_TYPE_BOOLEAN)
		{
			boolean booleanCellData =  xlsCell.getBooleanCellValue();
			CellData = booleanCellData;
		}	*/	
		return CellData;
	}
	catch (Exception e)
	{
		return"";
	}
}
 
開發者ID:GladsonAntony,項目名稱:WebAutomation_AllureParallel,代碼行數:29,代碼來源:ExcelUtils.java

示例13: cellVal

private String cellVal(Cell cell) {
	String result = "";
	if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) 
		result = String.valueOf(cell.getNumericCellValue());
	else if (cell.getCellType() == Cell.CELL_TYPE_STRING) 
		result = cell.getStringCellValue();
	else
		result = "NOT SUPPORTED";
	
	return result;
}
 
開發者ID:adelbs,項目名稱:ISO8583,代碼行數:11,代碼來源:ExcelReader.java

示例14: getCellData_XLSX

/** To get cell data from Excel-XLSX */
public static Object getCellData_XLSX(int RowNum, int ColNum) throws Exception
{
	Object CellData = null;
	try
	{
		xlsxCell = xlsxWorkSheet.getRow(RowNum).getCell(ColNum);
		if(xlsxCell.getCellType() == Cell.CELL_TYPE_STRING )
		{
			String stringCellData = xlsxCell.getStringCellValue();
			CellData = stringCellData;
		}
		/*		else if(xlsxCell.getCellType() == Cell.CELL_TYPE_NUMERIC)
		{
			double numericCellData =  xlsxCell.getNumericCellValue();
			CellData = numericCellData;
		}
		else if(xlsxCell.getCellType() == Cell.CELL_TYPE_BOOLEAN)
		{
			boolean booleanCellData =  xlsxCell.getBooleanCellValue();
			CellData = booleanCellData;
		}	*/	
		return CellData;
	}
	catch (Exception e)
	{
		return"";
	}
}
 
開發者ID:GladsonAntony,項目名稱:WebAutomation_AllureParallel,代碼行數:29,代碼來源:ExcelUtils.java

示例15: getBooleanValue

private boolean getBooleanValue(Cell cell) {
	switch (getCellType(cell)) {
	case Cell.CELL_TYPE_BOOLEAN:
		return cell.getBooleanCellValue();
	case Cell.CELL_TYPE_NUMERIC:
		return Double.compare(cell.getNumericCellValue(), 0) != 0;
	case Cell.CELL_TYPE_STRING:
		return Boolean.valueOf(cell.getStringCellValue());
	default:
		return false;
	}
}
 
開發者ID:xinufo,項目名稱:teemo,代碼行數:12,代碼來源:RowExcelImpl.java


注:本文中的org.apache.poi.ss.usermodel.Cell.CELL_TYPE_STRING屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。