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


Java Cell類代碼示例

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


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

示例1: getCellValue

import org.apache.poi.ss.usermodel.Cell; //導入依賴的package包/類
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;
}
 
開發者ID:junrui-zhao,項目名稱:Educational-Management-System,代碼行數:27,代碼來源:ClassroomServiceImpl.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: print

import org.apache.poi.ss.usermodel.Cell; //導入依賴的package包/類
public void print () {
	Sheet sheet =  getOrCreateSummary();
	Iterator<Row> rows = sheet.rowIterator();
	int index=0;
	while (rows.hasNext()) {
		Row row = (Row) rows.next();
		System.out.println("Row ---> " + index);
		Spliterator<Cell> cells = row.spliterator();
		cells.forEachRemaining(new Consumer<Cell> () {
			@Override
			public void accept(Cell cell) {
				System.out.print(cell.toString());
				System.out.print(";");
			}
		});
		System.out.println();
		index++;
	}
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:20,代碼來源:XLTestSummarySheet.java

示例5: readRow

import org.apache.poi.ss.usermodel.Cell; //導入依賴的package包/類
@Override
public IRow readRow() {
	SheetData vData = getLocalData();
	int vRowIndex = vData.getCurrentIndex();
	if (vRowIndex < vData.getRowCount()) {
		Row vRow = vData.getSheet().getRow(vRowIndex);
		String[] vTitles = vData.getTitles();
		Cell[] vValues = new Cell[vTitles.length];
		for (int i = 0; i < vTitles.length; ++i) {
			Cell vCell = vRow.getCell(i, MissingCellPolicy.CREATE_NULL_AS_BLANK);
			vValues[i] = vCell;
		}
		vData.setCurrentIndex(vRowIndex + 1);
		return new RowExcelImpl(vRowIndex, vTitles, vValues);
	}
	// read over, remove the local data
	removeLocalData();
	return null;
}
 
開發者ID:xinufo,項目名稱:teemo,代碼行數:20,代碼來源:ExcelReader.java

示例6: set

import org.apache.poi.ss.usermodel.Cell; //導入依賴的package包/類
public void set(int sheetIndex, int x_index, int y_index, String value) {
    try {
        if (wb == null) throw new Exception("未打開文件");
        Sheet sheet = wb.getSheetAt(sheetIndex);
        Row row = null;
        Cell cell = null;
        row = sheet.getRow(x_index);
        if (row == null) {
            row = sheet.createRow(x_index);
        }
        cell = row.getCell(y_index);
        if (cell == null) {
            cell = row.createCell(y_index);
        }
        cell.setCellValue(value);
        save();
    } catch (Exception e) {
        logger.error(e.getMessage());
    }
}
 
開發者ID:BetaSummer,項目名稱:sztw,代碼行數:21,代碼來源:HSSF.java

示例7: readExcelFile

import org.apache.poi.ss.usermodel.Cell; //導入依賴的package包/類
/**
 * Método que se encarga de leer el libro de excel
 * cuya ruta recibimos en el constructor y devuelve una lista 
 * de ciudadanos
 * @return lista de Usuarios de la base de datos
 */
public List<CitizenDB> readExcelFile(){
	List<CitizenDB> citizens = new ArrayList<CitizenDB>(); 
	// para cada una de las hojas presentes en el documento de excel
	for(int i=0;i < workbook.getNumberOfSheets();i++){
		XSSFSheet sheet = this.workbook.getSheetAt(i);
		Iterator<Row> rowIterator = sheet.iterator();
		Row row;
		int counter = 0;
		//para cada fila de la hoja
		while(rowIterator.hasNext()){
			row = rowIterator.next();
			if (counter > 0) { //omitimos la cabecera (hay que mirar si hay un metodo de la API)
				Iterator<Cell> cellIterator = row.cellIterator();
				int j = 0;
				CitizenDB user = new CitizenDB();
				while (cellIterator.hasNext()) 	
					this.insertCitizenField(user, j++, cellIterator.next());	
				user.setPassword(new GenerationPassword().passwordGenerator());
				citizens.add(user);
			}
			counter++;
		}
	}
	return citizens;
}
 
開發者ID:Arquisoft,項目名稱:dashboard1b,代碼行數:32,代碼來源:AdapterPoi.java

示例8: getInsertStatementForCell

import org.apache.poi.ss.usermodel.Cell; //導入依賴的package包/類
private String getInsertStatementForCell(String userId, Cell cell) {
    String answer = null;
    switch (cell.getColumnIndex()) {
    case 1:
        answer = getInsertStatement(userId, 2237);
        break;
    case 2:
        answer = getInsertStatement(userId, 4352);
        break;
    case 3:
        answer = getInsertStatement(userId, 3657);
        break;
    case 4:
        answer = getInsertStatement(userId, 5565);
        break;
    }
    
    return answer;
}
 
開發者ID:jeffgbutler,項目名稱:practical-functional-java,代碼行數:20,代碼來源:AwfulScriptGeneratorRefactoredStep5.java

示例9: next

import org.apache.poi.ss.usermodel.Cell; //導入依賴的package包/類
@Override
public void next(ProgressListener listener) {
	currentRow++;
	while (currentRow < totalNumberOfRows + rowOffset && emptyRows[currentRow - rowOffset]) {
		currentRow++;
	}

	if (currentRow >= totalNumberOfRows + rowOffset) {
		throw new NoSuchElementException("No further row in excel sheet.");
	}

	currentRowCells = new Cell[attributeNames.length];
	int columnCounter = 0;
	for (int c = 0; c < totalNumberOfColumns; c++) {
		if (!emptyColumns[c]) {
			currentRowCells[columnCounter] = sheet.getRow(currentRow).getCell(c + columnOffset);
			columnCounter++;
		}
	}

	// notifying progress listener
	if (listener != null) {
		listener.setCompleted(currentRow);
	}
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:26,代碼來源:Excel2007ResultSet.java

示例10: feedDetailsSheet

import org.apache.poi.ss.usermodel.Cell; //導入依賴的package包/類
public void feedDetailsSheet(Sheet sheet, boolean exportAsTemplate, List<XLTestStep> xLTestSteps) {
	int index = 0;
	for (XLTestStep xLTestStep : xLTestSteps) {
		index++;
		Row row = sheet.createRow(index);
		Cell cell = row.createCell(STEPNAME_INDEX);
		cell.setCellValue(xLTestStep.getName());
		cell = row.createCell(EXPECTED_OR_ACTION_INDEX);
		cell.setCellValue(xLTestStep.getExpected());
		cell = row.createCell(RESULT_INDEX);
		if (exportAsTemplate)
			cell.setCellValue("");
		else
			cell.setCellValue(xLTestStep.getActual());
		cell = row.createCell(STATUS_INDEX);
		formatCellStatus(sheet, cell);
		if (exportAsTemplate)
			cell.setCellValue("");
		else
			cell.setCellValue(Integer.parseInt(xLTestStep.getStatus()));
	}
	this.autoSize(sheet, new int[] { 0, 1, 2, 3 });
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:24,代碼來源:XLTestDetailsSheet.java

示例11: readLine

import org.apache.poi.ss.usermodel.Cell; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public String[] readLine(int line, boolean readResult) throws TechnicalException {
    final Sheet sheet = workbook.getSheetAt(0);
    final Row row = sheet.getRow(line);
    if (row == null || "".equals(readCell(row.getCell(0)))) {
        return null;
    } else {
        final String[] ret = readResult ? new String[columns.size()] : new String[columns.size() - 1];
        Cell cell;
        for (int i = 0; i < ret.length; i++) {
            if ((cell = row.getCell(i)) == null) {
                ret[i] = "";
            } else {
                ret[i] = readCell(cell);
            }
        }
        return ret;
    }
}
 
開發者ID:NoraUi,項目名稱:NoraUi,代碼行數:23,代碼來源:ExcelDataProvider.java

示例12: setCellValue

import org.apache.poi.ss.usermodel.Cell; //導入依賴的package包/類
protected void setCellValue(Cell sheetCell, Object value, Class<?> valueType, Object propId) {
    if (null != value) {
        if (!isNumeric(valueType)) {
            if (java.util.Date.class.isAssignableFrom(valueType)) {
                sheetCell.setCellValue((Date) value);
            } else {
                sheetCell.setCellValue(createHelper.createRichTextString(value.toString()));
            }
        } else {
            try {
                // parse all numbers as double, the format will determine how they appear
                final Double d = Double.parseDouble(value.toString());
                sheetCell.setCellValue(d);
            } catch (final NumberFormatException nfe) {
                LOGGER.warning("NumberFormatException parsing a numeric value: " + nfe);
                sheetCell.setCellValue(createHelper.createRichTextString(value.toString()));
            }
        }
    }
}
 
開發者ID:TFyre,項目名稱:vaadin-gridexport,代碼行數:21,代碼來源:ExcelExport.java

示例13: formatCellStatus

import org.apache.poi.ss.usermodel.Cell; //導入依賴的package包/類
protected void formatCellStatus(Sheet sheet, Cell cell) {
	cell.setCellStyle(styles.get("status"));
	SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();
	ConditionalFormattingRule ruleGreen = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "1");
	PatternFormatting fill1 = ruleGreen.createPatternFormatting();
	fill1.setFillBackgroundColor(IndexedColors.GREEN.index);
	fill1.setFillPattern(PatternFormatting.SOLID_FOREGROUND);
	//
	ConditionalFormattingRule ruleRed = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "0");
	PatternFormatting fill2 = ruleRed.createPatternFormatting();
	fill2.setFillBackgroundColor(IndexedColors.RED.index);
	fill2.setFillPattern(PatternFormatting.SOLID_FOREGROUND);
	//
	ConditionalFormattingRule ruleOrange = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "2");
	PatternFormatting fill3 = ruleOrange.createPatternFormatting();
	fill3.setFillBackgroundColor(IndexedColors.ORANGE.index);
	fill3.setFillPattern(PatternFormatting.SOLID_FOREGROUND);
	//
	String name = CellReference.convertNumToColString(cell.getColumnIndex());
	String location = "$" + name + "$" + cell.getRowIndex() + ":$" + name + "$" + (cell.getRowIndex() + 1);

	CellRangeAddress[] regions = { CellRangeAddress.valueOf(location) };
	ConditionalFormattingRule[] cfRules = new ConditionalFormattingRule[] { ruleGreen, ruleRed, ruleOrange };
	sheetCF.addConditionalFormatting(regions, cfRules);
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:26,代碼來源:XLTest.java

示例14: writeTitle

import org.apache.poi.ss.usermodel.Cell; //導入依賴的package包/類
/**
 * 向當前Sheet第一行(1-based)寫入標題,若用戶沒有開啟寫入標題總開關(即{@link #isWriteTitle}為false),
 * 或者{@link #titles}為空則不會做任何操作
 */
private void writeTitle() {
    if (!this.isWriteTitle || this.titles == null || this.titles.isEmpty()) {
        return;
    }
    this.currentRowInSheet++;
    Row row = this.currentSheetPO.createRow(this.currentRowInSheet);
    row.setHeight(this.rowHeight < 0 ? -1 : this.rowHeight);
    for (int i = 0; i < this.titles.size(); i++) {
        Cell cell = row.createCell(i);
        cell.setCellStyle(this.defaultTitleCellStyle);
        cell.setCellValue(this.titles.get(i));
    }
    this.realRowInSheet++;
    this.realRowInExcel++;
}
 
開發者ID:FlyingHe,項目名稱:UtilsMaven,代碼行數:20,代碼來源:XLSXWriter.java

示例15: 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


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