当前位置: 首页>>代码示例>>Java>>正文


Java XSSFCell.getCellType方法代码示例

本文整理汇总了Java中org.apache.poi.xssf.usermodel.XSSFCell.getCellType方法的典型用法代码示例。如果您正苦于以下问题:Java XSSFCell.getCellType方法的具体用法?Java XSSFCell.getCellType怎么用?Java XSSFCell.getCellType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.poi.xssf.usermodel.XSSFCell的用法示例。


在下文中一共展示了XSSFCell.getCellType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCellValue

import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
/**
 * Gets the cell value.
 *
 * @param cell the cell
 * @return the cell value
 */
private String getCellValue( XSSFCell cell )
{
	if (cell != null)
	{
		switch (cell.getCellType())
		{
			case XSSFCell.CELL_TYPE_BLANK:
				return null;
			case XSSFCell.CELL_TYPE_BOOLEAN:
				return String.valueOf( cell.getBooleanCellValue() );
			case XSSFCell.CELL_TYPE_NUMERIC:
				return String.valueOf( ( int ) cell.getNumericCellValue() );
			case XSSFCell.CELL_TYPE_STRING:
				return cell.getRichStringCellValue().toString();

		}
	}
	return null;
}
 
开发者ID:xframium,项目名称:xframium-java,代码行数:26,代码来源:ExcelDataProvider.java

示例2: get

import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
public Object get(XSSFCell cell) {
    if (cell != null) {
        int cellType = cell.getCellType();
        switch (cellType) {
            case Cell.CELL_TYPE_NUMERIC:
                return cell.getNumericCellValue();
            case Cell.CELL_TYPE_BOOLEAN:
                return cell.getBooleanCellValue();
            default:
                try {
                    return cell.getStringCellValue();
                } catch (IllegalStateException mismatch) {
                    return null;
                }
        }
    } else {
        return null;
    }

}
 
开发者ID:theysay,项目名称:preceive-batch,代码行数:21,代码来源:XLSXSourceProvider.java

示例3: getCellValue

import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
/**
 * Gets the cell value.
 *
 * @param cell the cell
 * @return the cell value
 */
private String getCellValue( XSSFCell cell )
{
	if (cell != null)
	{
		switch (cell.getCellType())
		{
			case XSSFCell.CELL_TYPE_BLANK:
				return null;
			case XSSFCell.CELL_TYPE_BOOLEAN:
				return String.valueOf( cell.getBooleanCellValue() );
			case XSSFCell.CELL_TYPE_NUMERIC:
				return String.valueOf( cell.getNumericCellValue() );
			case XSSFCell.CELL_TYPE_STRING:
				return cell.getRichStringCellValue().toString();
		}
	}
	return null;
}
 
开发者ID:xframium,项目名称:xframium-java,代码行数:25,代码来源:ExcelCloudProvider.java

示例4: getCellValue

import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
/**
 * Gets the cell value.
 *
 * @param cell the cell
 * @return the cell value
 */
private String getCellValue( XSSFCell cell )
{
	if (cell != null)
	{
		switch (cell.getCellType())
		{
			case XSSFCell.CELL_TYPE_BLANK:
				return null;
			case XSSFCell.CELL_TYPE_BOOLEAN:
				return String.valueOf( cell.getBooleanCellValue() );
			case XSSFCell.CELL_TYPE_NUMERIC:
			{
			    String useValue = String.valueOf( cell.getNumericCellValue() );
			    if ( useValue.endsWith( ".0" ) )
			        return useValue.split( "\\." )[0];
			    else
			        return useValue;
			}
			case XSSFCell.CELL_TYPE_STRING:
				return cell.getRichStringCellValue().toString();
		}
	}
	return null;
}
 
开发者ID:xframium,项目名称:xframium-java,代码行数:31,代码来源:ExcelPageDataProvider.java

示例5: getCellValue

import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
private String getCellValue( XSSFCell cell )
{
    if (cell != null )
    {
        switch (cell.getCellType())
        {
            case XSSFCell.CELL_TYPE_BLANK:
                return null;
            case XSSFCell.CELL_TYPE_BOOLEAN:
                return String.valueOf( cell.getBooleanCellValue() );
            case XSSFCell.CELL_TYPE_NUMERIC:
                return String.valueOf( cell.getNumericCellValue() );
            case XSSFCell.CELL_TYPE_STRING:
                return cell.getRichStringCellValue().toString();
        }
    }
    return null;
}
 
开发者ID:xframium,项目名称:xframium-java,代码行数:19,代码来源:ExcelKeyWordProvider.java

示例6: updateCellValue

import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:linearblue,项目名称:ExcelInjector,代码行数:23,代码来源:ExcelTableInjector.java

示例7: getValue

import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
public static Object getValue(XSSFSheet sheet, int row, int col) {
    try {

        XSSFRow xrow = sheet.getRow(row);
        XSSFCell cell = xrow.getCell(col);

        switch (cell.getCellType()) {
            case Cell.CELL_TYPE_NUMERIC:
                return cell.getNumericCellValue();
            case Cell.CELL_TYPE_STRING:
                return (new DateComponentFormatter(
                        ComponentManager.getInstance().getComponentFormatDefaults().getSelectedDateFormat()))
                        .stringToValue(cell.getStringCellValue());
        }

    } catch (ParseException e) {
        e.printStackTrace();
    }

    return null;
}
 
开发者ID:pghazal,项目名称:NoMoreLine,代码行数:22,代码来源:ExcelUtils.java

示例8: validate

import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
@Override
public ValidationResult validate(XSSFCell cell) {
	if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
		String stringCellValue = cell.getStringCellValue();
		int length;
		if (stringCellValue == null) {
			length = 0;
		} else {
			length = stringCellValue.length();
		}
		if (!operator.check((double) length)) {
			return new ValidationResultImpl(cell.getSheet().getSheetName(), cell.getReference(), false, "Error!");
		}
	} else {
		// TODO how to handle this situation
	}
	return null;
}
 
开发者ID:ykaragol,项目名称:poi-data-validation,代码行数:19,代码来源:TextLengthValidator.java

示例9: getStrCellVal

import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
/**
 * 获取单元格字符串值
 *
 * @param cell
 * @return
 *
 */
public static String getStrCellVal(XSSFCell cell) {
    if (cell == null) {
        // 如果参数对象为空,
        // 则直接退出!
        return null;
    }

    switch (cell.getCellType()) {
    case XSSFCell.CELL_TYPE_STRING:
        return cell.getStringCellValue();
    case XSSFCell.CELL_TYPE_BOOLEAN:
        return cell.getBooleanCellValue() ? "true" : "false";
    default:
        // 抛出异常
        throw new XlsxTmplError(MessageFormat.format(
            ERR_CELL_TYPE,
            getSheetIndex(cell) + 1,
            getSheetName(cell),
            String.valueOf(cell.getRowIndex() + 1),
            getColName(cell.getColumnIndex()),
            String.class.getName(),
            getCellTypeName(cell)
        ));
    }
}
 
开发者ID:hjj2017,项目名称:xgame-code_server,代码行数:33,代码来源:XSSFUtil.java

示例10: fromXSSFRowtoCSV

import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
private String fromXSSFRowtoCSV(XSSFRow row){
    StringBuffer csvRow = new StringBuffer();
    int l = row.getLastCellNum();
    for (int i=0;i<l;i++){
        XSSFCell cell = row.getCell((short)i);
        String cellValue = "";
        if (cell == null || cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
            cellValue = "";
        } else if (cell.getCellType()== HSSFCell.CELL_TYPE_STRING){
            cellValue = "\"" + cell.getStringCellValue() + "\"";
        } else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
            double value = cell.getNumericCellValue();
            cellValue = getNumberFormat().format(value);
            cellValue = "\"" + cellValue + "\"";
        }

        csvRow.append(cellValue);

        if (i<l){
            csvRow.append(getCsvDelimiter().toCharArray()[0]);
        }
    }
    return csvRow.toString();
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:25,代码来源:SpreadsheetUploadBean.java

示例11: cellValues2String

import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:fhm84,项目名称:jexunit,代码行数:36,代码来源:ExcelLoader.java

示例12: getValue

import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
private static String getValue(XSSFCell xssFCell) {
	 String str = null;
	 if(xssFCell == null){
		 return str;
	 }
	 if (xssFCell.getCellType() == XSSFCell.CELL_TYPE_BOOLEAN) {
		 str = String.valueOf(xssFCell.getBooleanCellValue());
	 } else if (xssFCell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) {
		 str = String.valueOf(new DecimalFormat("#").format(xssFCell.getNumericCellValue()));
	 } else {
		 str = String.valueOf(xssFCell.getStringCellValue());
	 }
	 return StringUtils.trim(str);
}
 
开发者ID:xujeff,项目名称:tianti,代码行数:15,代码来源:ExcelUtils.java

示例13: copyCell

import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
/**
 * @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;
    }

}
 
开发者ID:likelet,项目名称:DAtools,代码行数:45,代码来源:Util.java

示例14: extractDataFromXls

import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
private static JSONArray extractDataFromXls(XSSFWorkbook wb) {
    XSSFSheet sheet = wb.getSheetAt(0);

    int rows = sheet.getPhysicalNumberOfRows();
    int cols = sheet.getRow(0).getPhysicalNumberOfCells();
    int startRow = 1; // Pular cabecalho.

    JsonObjectCreator jsonObjCreator = new FedDepJsonObjectCreator();
    JSONArray jArr = new JSONArray();
    for(int row = startRow; row < rows; row++) {
        XSSFRow xssfRow = sheet.getRow(row);
        if(xssfRow != null) {

            String[] rowData = new String[cols];
            for(int col = 0; col < cols; col++) {
                XSSFCell cell = xssfRow.getCell(col);
                if(cell != null) {
                    String datum;
                    if (XSSFCell.CELL_TYPE_STRING == cell.getCellType()) {
                        datum = cell.getStringCellValue();
                    }
                    else if (XSSFCell.CELL_TYPE_NUMERIC == cell.getCellType()) {
                        datum = String.valueOf(cell.getNumericCellValue());
                    }
                    else {
                        System.out.println("A célula: [" + row + "," + col + "] não contém um String e nem um Número.");
                        datum = "";
                    }

                    rowData[col] = datum;
                }
            }

            JSONObject jObj = jsonObjCreator.processLine(rowData);
            jArr.add(jObj);
        }
    }

    return jArr;
}
 
开发者ID:TekkLabs,项目名称:memoria-politica,代码行数:41,代码来源:FedDepXlsxConverter.java

示例15: shiftRange

import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
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());
                    }
                }
            }
        }
    }
 
开发者ID:linearblue,项目名称:ExcelInjector,代码行数:37,代码来源:ExcelTableInjector.java


注:本文中的org.apache.poi.xssf.usermodel.XSSFCell.getCellType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。