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


Java XSSFCell類代碼示例

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


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

示例1: writeXLSXFile

import org.apache.poi.xssf.usermodel.XSSFCell; //導入依賴的package包/類
public static void writeXLSXFile() throws IOException {

			// @SuppressWarnings("resource")
			XSSFWorkbook wbObj = new XSSFWorkbook();
			XSSFSheet sheet = wbObj.createSheet(sheetName);
			for (int row = 0; row < tableData.size(); row++) {
				XSSFRow rowObj = sheet.createRow(row);
				rowData = tableData.get(row);
				for (int col = 0; col < rowData.size(); col++) {
					XSSFCell cell = rowObj.createCell(col);
					cell.setCellValue(rowData.get(col));
					logger.info("Writing " + row + " " + col + "  " + rowData.get(col));
				}
			}
			FileOutputStream fileOut = new FileOutputStream(excelFileName);
			wbObj.write(fileOut);
			wbObj.close();
			fileOut.flush();
			fileOut.close();
		}
 
開發者ID:sergueik,項目名稱:SWET,代碼行數:21,代碼來源:TableEditorEx.java

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

示例3: insertDedicatedStyleCell

import org.apache.poi.xssf.usermodel.XSSFCell; //導入依賴的package包/類
public static void insertDedicatedStyleCell(XSSFRow row,int col,XSSFCellStyle style,String value){
	String message="XSSFRow or XSSFCellStyle must not be null!";
	Objects.requireNonNull(row, () -> message);
	Objects.requireNonNull(style, () -> message);
	XSSFCell cell=createCellIfNotPresent(row,col);
	setCellProperties(createCellIfNotPresent(row, col), value, style);
}
 
開發者ID:gp15237125756,項目名稱:PoiExcelExport,代碼行數:8,代碼來源:XSSFCellUtil.java

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

示例5: microsoftExcelDocumentToString

import org.apache.poi.xssf.usermodel.XSSFCell; //導入依賴的package包/類
private static String microsoftExcelDocumentToString(InputStream inputStream) throws IOException, OpenXML4JException, XmlException {
    StringBuilder sb = new StringBuilder();

    try (InputStream excelStream = new BufferedInputStream(inputStream)) {
        if (POIFSFileSystem.hasPOIFSHeader(excelStream)) { // Before 2007 format files
            POIFSFileSystem excelFS = new POIFSFileSystem(excelStream);
            ExcelExtractor excelExtractor = new ExcelExtractor(excelFS);
            sb.append(excelExtractor.getText());
            excelExtractor.close();
        } else { // New format
            XSSFWorkbook workBook = new XSSFWorkbook(excelStream);
            int numberOfSheets = workBook.getNumberOfSheets();
            for (int i = 0; i < numberOfSheets; i++) {
                XSSFSheet sheet = workBook.getSheetAt(0);
                Iterator<Row> rowIterator = sheet.rowIterator();
                while (rowIterator.hasNext()) {
                    XSSFRow row = (XSSFRow) rowIterator.next();
                    Iterator<Cell> cellIterator = row.cellIterator();
                    while (cellIterator.hasNext()) {
                        XSSFCell cell = (XSSFCell) cellIterator.next();
                        sb.append(cell.toString());
                        sb.append(" ");
                    }
                    sb.append("\n");
                }
                sb.append("\n");
            }
        }
    }

    return sb.toString();
}
 
開發者ID:polarsys,項目名稱:eplmp,代碼行數:33,代碼來源:IndexerUtils.java

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

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

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

示例9: copyRow

import org.apache.poi.xssf.usermodel.XSSFCell; //導入依賴的package包/類
/**
 * @param srcSheet the sheet to copy.
 * @param destSheet the sheet to create.
 * @param srcRow the row to copy.
 * @param destRow the row to create.
 * @param styleMap -
 */
public static void copyRow(XSSFSheet srcSheet, XSSFSheet destSheet, XSSFRow srcRow, XSSFRow destRow, Map<Integer, XSSFCellStyle> styleMap) {
    // manage a list of merged zone in order to not insert two times a merged zone  
    Set<CellRangeAddressWrapper> mergedRegions = new TreeSet<CellRangeAddressWrapper>();
    destRow.setHeight(srcRow.getHeight());
    // pour chaque row  
    for (int j = srcRow.getFirstCellNum(); j <= srcRow.getLastCellNum(); j++) {
        if(j<0){
        }else{
            XSSFCell oldCell = srcRow.getCell(j);   // ancienne cell  
        XSSFCell newCell = destRow.getCell(j);  // new cell   
        if (oldCell != null) {
            if (newCell == null) {
                newCell = destRow.createCell(j);
            }
            // copy chaque cell  
            copyCell(oldCell, newCell, styleMap);
                  // copy les informations de fusion entre les cellules  
            //System.out.println("row num: " + srcRow.getRowNum() + " , col: " + (short)oldCell.getColumnIndex());  
            CellRangeAddress mergedRegion = getMergedRegion(srcSheet, srcRow.getRowNum(), (short) oldCell.getColumnIndex());

            if (mergedRegion != null) {
                //System.out.println("Selected merged region: " + mergedRegion.toString());  
                CellRangeAddress newMergedRegion = new CellRangeAddress(mergedRegion.getFirstRow(), mergedRegion.getLastRow(), mergedRegion.getFirstColumn(), mergedRegion.getLastColumn());
                //System.out.println("New merged region: " + newMergedRegion.toString());  
                CellRangeAddressWrapper wrapper = new CellRangeAddressWrapper(newMergedRegion);
                if (isNewMergedRegion(wrapper, mergedRegions)) {
                    mergedRegions.add(wrapper);
                    destSheet.addMergedRegion(wrapper.range);
                }
            }
        }
        }
        
    }

}
 
開發者ID:likelet,項目名稱:DAtools,代碼行數:44,代碼來源:Util.java

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

示例11: readXlsx

import org.apache.poi.xssf.usermodel.XSSFCell; //導入依賴的package包/類
/**
 * Read the Excel 2010
 * 
 * @param path
 *            the path of the excel file
 * @return
 * @throws IOException
 */
public static String readXlsx(String path) throws IOException {
	InputStream is = new FileInputStream(path);
	XSSFWorkbook xssfWorkbook = new XSSFWorkbook(is);
	StringBuffer sb = new StringBuffer("");
	// Read the Sheet
	for (int numSheet = 0; numSheet < xssfWorkbook.getNumberOfSheets(); numSheet++) {
		XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(numSheet);
		if (xssfSheet == null) {
			continue;
		}
		// Read the Row
		for (int rowNum = 1; rowNum <= xssfSheet.getLastRowNum(); rowNum++) {
			XSSFRow xssfRow = xssfSheet.getRow(rowNum);
			if (xssfRow != null) {
				XSSFCell no = xssfRow.getCell(0);
				XSSFCell name = xssfRow.getCell(1);
				sb.append(no + ":" + name);
				sb.append(";");
			}
		}
	}
	return sb.toString().substring(0, sb.toString().length() - 1);
}
 
開發者ID:wufeisoft,項目名稱:data,代碼行數:32,代碼來源:ReadExcelUtil.java

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

示例13: stringValueOf

import org.apache.poi.xssf.usermodel.XSSFCell; //導入依賴的package包/類
protected String stringValueOf(CellValue value) {
    switch (value.getCellType()) {
        case XSSFCell.CELL_TYPE_STRING:
            return value.getStringValue();
        case XSSFCell.CELL_TYPE_NUMERIC:
            return String.valueOf(value.getNumberValue());
        case XSSFCell.CELL_TYPE_BLANK:
            return "";
        case XSSFCell.CELL_TYPE_BOOLEAN:
            return String.valueOf(value.getBooleanValue());
        case XSSFCell.CELL_TYPE_ERROR:
            return "error";
        default:
            return "unknown";
    }
}
 
開發者ID:aalexandrov,項目名稱:arch-tools,代碼行數:17,代碼來源:ClusteringService.java

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

示例15: getCellTypeName

import org.apache.poi.xssf.usermodel.XSSFCell; //導入依賴的package包/類
/**
 * 獲取單元格類型名稱
 *
 * @param cell
 * @return
 *
 */
public static String getCellTypeName(XSSFCell cell) {
    if (cell == null) {
        return "null";
    }

    switch (cell.getCellType()) {
    case XSSFCell.CELL_TYPE_BLANK: return "CELL_TYPE_BLANK";
    case XSSFCell.CELL_TYPE_BOOLEAN: return "CELL_TYPE_BOOLEAN";
    case XSSFCell.CELL_TYPE_ERROR: return "CELL_TYPE_ERROR";
    case XSSFCell.CELL_TYPE_FORMULA: return "CELL_TYPE_FORMULA";
    case XSSFCell.CELL_TYPE_NUMERIC: return "CELL_TYPE_NUMERIC";
    case XSSFCell.CELL_TYPE_STRING: return "CELL_TYPE_STRING";
    default: return "unknown";
    }
}
 
開發者ID:hjj2017,項目名稱:xgame-code_server,代碼行數:23,代碼來源:XSSFUtil.java


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