当前位置: 首页>>代码示例>>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;未经允许,请勿转载。