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


Java Cell.getStringCellValue方法代碼示例

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


在下文中一共展示了Cell.getStringCellValue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getCharValue

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
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,代碼行數:18,代碼來源:RowExcelImpl.java

示例2: getHeaderMap

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
/**
 * 獲取excel列表頭
 *
 * @param titleRow excel行
 * @param clz      類型
 * @return ExcelHeader集合
 * @throws InstantiationException 異常
 * @throws IllegalAccessException 異常
 */
public static Map<Integer, ExcelHeader> getHeaderMap(Row titleRow, Class<?> clz)
        throws InstantiationException, IllegalAccessException {

    List<ExcelHeader> headers = getHeaderList(clz);
    Map<Integer, ExcelHeader> maps = new HashMap<>();
    for (Cell c : titleRow) {
        String title = c.getStringCellValue();
        for (ExcelHeader eh : headers) {
            if (eh.getTitle().equals(title.trim())) {
                maps.put(c.getColumnIndex(), eh);
                break;
            }
        }
    }
    return maps;
}
 
開發者ID:Crab2died,項目名稱:Excel4J,代碼行數:26,代碼來源:Utils.java

示例3: setSheetData

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
private void setSheetData(SheetData data, String group) {
	data.setCurrentGroup(group);
	// start from 1
	data.setCurrentIndex(1);
	// get sheet
	Sheet vSheet = getWorkBook().getSheet(group);
	Assert.notNull(vSheet, "Can't get sheet with name: " + group);
	data.setSheet(vSheet);
	// get row number
	int vRowCount = vSheet.getLastRowNum() + 1;
	data.setRowCount(vRowCount);
	// get first row
	Row vRow = vSheet.getRow(0);
	Assert.notNull(vRow, "Invalid format: first row must be title");
	// get column number
	int vColumnCount = vRow.getLastCellNum();
	String[] vTitles = new String[vColumnCount];
	// read titles
	for (int i = 0; i < vColumnCount; ++i) {
		Cell vCell = vRow.getCell(i);
		vTitles[i] = vCell.getStringCellValue();
	}
	data.setTitles(vTitles);
}
 
開發者ID:xinufo,項目名稱:teemo,代碼行數:25,代碼來源:ExcelReader.java

示例4: mergeRows

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
/**
 * 合並行
 */
//TODO 暫時支持兩行表頭
private void mergeRows(Sheet sheet, CellStyle cellStyle, ExcelMeta excelMeta) {

    Row row = null;
    Cell cell = null;
    String[] lastRowVals = new String[excelMeta.getTitleColumnNum()];
    for (int r = 0; r < excelMeta.getTitleRowNum(); r++) {
        for (int c = 0; c < excelMeta.getTitleColumnNum(); c++) {
            row = sheet.getRow(r);
            cell = row.getCell(c);
            if (r == 0) {
                lastRowVals[c] = cell.getStringCellValue();
            } else {
                if (StringUtils.equals(lastRowVals[c], cell.getStringCellValue())) {
                    cell.setCellValue("");
                    sheet.addMergedRegion(new CellRangeAddress(0, r, c, c));
                    Cell nowCell = sheet.getRow(0).getCell(c);
                    nowCell.setCellStyle(cellStyle);
                }
            }

        }
    }

}
 
開發者ID:warlock-china,項目名稱:azeroth,代碼行數:29,代碼來源:ExcelWriter.java

示例5: isBlankRow

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
/**
 * 判斷空行
 */
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,代碼行數:36,代碼來源:BaseReadUtil.java

示例6: parse

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
public Map<String, BoundaryPoint> parse(InputStream is) throws IOException {
    Map<String, BoundaryPoint> boundaryPoints = new HashMap<>();
    HSSFWorkbook workbook = new HSSFWorkbook(is);
    HSSFSheet sheet = workbook.getSheetAt(0);
    Iterator<Row> rowIterator = sheet.iterator();
    rowIterator.next();
    rowIterator.next();
    while (rowIterator.hasNext()) {
        Row row = rowIterator.next();
        Cell boundaryPointNameCell = row.getCell(13);
        Cell borderFromCell = row.getCell(14);
        Cell borderToCell = row.getCell(15);
        String boundaryPointName = boundaryPointNameCell.getStringCellValue();
        if (boundaryPointName.equals("-")) {
            continue;
        }
        Country borderFrom = toCountry(borderFromCell.getStringCellValue());
        Country borderTo = toCountry(borderToCell.getStringCellValue());
        boundaryPoints.put(boundaryPointName, new BoundaryPoint(boundaryPointName, borderFrom, borderTo));
    }
    return boundaryPoints;
}
 
開發者ID:powsybl,項目名稱:powsybl-core,代碼行數:23,代碼來源:BoundaryPointXlsParser.java

示例7: getStringValue

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
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);
	}
}
 
開發者ID:xinufo,項目名稱:teemo,代碼行數:19,代碼來源:RowExcelImpl.java

示例8: getCellValue

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
/**
 * 獲取單元格內容
 *
 * @param c 單元格
 * @return 單元格內容
 */
public static String getCellValue(Cell c) {
    String o;
    switch (c.getCellTypeEnum()) {
        case BLANK:
            o = "";
            break;
        case BOOLEAN:
            o = String.valueOf(c.getBooleanCellValue());
            break;
        case FORMULA:
            o = calculationFormula(c);
            break;
        case NUMERIC:
            o = String.valueOf(c.getNumericCellValue());
            o = matchDoneBigDecimal(o);
            o = RegularUtils.converNumByReg(o);
            break;
        case STRING:
            o = c.getStringCellValue();
            break;
        default:
            o = null;
            break;
    }
    return o;
}
 
開發者ID:Crab2died,項目名稱:Excel4J,代碼行數:33,代碼來源:Utils.java

示例9: appendItemCn

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
public static void appendItemCn(BufferedWriter out, Cell cell1, Cell cell2) throws IOException {
    if (cell1 == null || cell2 == null) {
        return;
    }
    String name = cell2.getStringCellValue().replaceAll("( )+", "_").toLowerCase();
    String value = cell1.getStringCellValue();
    if(StringUtils.isEmpty(name) && StringUtils.isEmpty(value)){
        return;
    }
    out.append(String.format("<string name=\"%s\">%s</string>", name, value));
    out.newLine();
}
 
開發者ID:linchaolong,項目名稱:ExcelParser,代碼行數:13,代碼來源:Excel2Xml.java

示例10: generate

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
@Override
public List<String> generate(Sheet sheet) {
    List<String> lines = new ArrayList<>();
    for (Row row : sheet) {
        Cell firstCell = row.getCell(0);
        if (firstCell != null) {
            String userId = firstCell.getStringCellValue();
            if (".".equals(userId.substring(1, 2))) {
                for (Cell cell : row) {
                    if (cell.getColumnIndex() == 0) {
                        continue;
                    }

                    if ("X".equals(cell.getStringCellValue())) {
                        switch (cell.getColumnIndex()) {
                        case 1:
                            lines.add(getInsertStatement(userId, 2237));
                            break;
                        case 2:
                            lines.add(getInsertStatement(userId, 4352));
                            break;
                        case 3:
                            lines.add(getInsertStatement(userId, 3657));
                            break;
                        case 4:
                            lines.add(getInsertStatement(userId, 5565));
                            break;
                        }
                    }
                }
            }
        }
    }

    return lines;
}
 
開發者ID:jeffgbutler,項目名稱:practical-functional-java,代碼行數:37,代碼來源:AwfulScriptGenerator.java

示例11: addInsertStatementsForRow

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
private void addInsertStatementsForRow(List<String> lines, Row row) {
    Cell firstCell = row.getCell(0);
    if (firstCell != null) {
        String userId = firstCell.getStringCellValue();
        if (isValidUserId(userId)) {
            addInsertStatementsForRow(lines, row, userId);
        }
    }
}
 
開發者ID:jeffgbutler,項目名稱:practical-functional-java,代碼行數:10,代碼來源:AwfulScriptGeneratorRefactoredStep1.java

示例12: getBoolean

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
public static Boolean getBoolean(Cell cell) {
    if (isNullCell(cell)) {
        return null;
    }
    if (Cell.CELL_TYPE_BOOLEAN == cell.getCellType()) {
        return cell.getBooleanCellValue();
    }
    if (Cell.CELL_TYPE_STRING == cell.getCellType()) {
        String value = cell.getStringCellValue();
        return "1".equals(value) || "是".equals(value);
    }
    throw new RuntimeException("can not convertWithConstructor cell value to Boolean!");
}
 
開發者ID:dengxiangjun,項目名稱:OfficeAutomation,代碼行數:14,代碼來源:CellConvert.java

示例13: getCellValue

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
private String getCellValue(final Cell cell, int count) {
	String cellValue = null;
	CellType ct = cell.getCellTypeEnum();
	switch (ct) {
	case STRING:
		cellValue = cell.getStringCellValue();
		break;
	case NUMERIC:
		cellValue = String.valueOf(cell.getNumericCellValue());
		break;
	case BOOLEAN:
		cellValue = String.valueOf(cell.getBooleanCellValue());
		break;
	case BLANK:
		if (count > -1) {
			cellValue = "BLANK" + String.valueOf(count);
		}
		break;
	case FORMULA:
		CellType cacheCellType = cell.getCachedFormulaResultTypeEnum(); {
		switch (cacheCellType) {
		case STRING:
			cellValue = cell.getStringCellValue();
			break;
		case NUMERIC:
			cellValue = String.valueOf(cell.getNumericCellValue());
			break;
		case BOOLEAN:
			cellValue = String.valueOf(cell.getBooleanCellValue());
			break;
		default:
			cellValue = cell.getCellFormula();
		}
	}
		break;
	default:
		cellValue = null;
	}
	return cellValue;
}
 
開發者ID:Stwissel,項目名稱:Excel2XML,代碼行數:41,代碼來源:E2xCmdline.java

示例14: getValue

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
/** 從表格之中讀取數據並進行處理
 * @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,代碼行數:46,代碼來源:ExcelImportUtil.java

示例15: getCellValue

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
/**
 * 獲取單元格值
 *
 * @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,代碼行數:42,代碼來源:ImportExcel.java


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