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


Java XSSFRow.getCell方法代码示例

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


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

示例1: copyRow

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的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

示例2: readXlsx

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的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

示例3: readHeader

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
private void readHeader(XSSFRow firstRow, int startCell,
		List<Cell> headerList, List<Cell> keyList) {
	for(int i = startCell; i < firstRow.getLastCellNum();  i++) {
		if(firstRow.getCell(i)!=null){
			String header = trim(firstRow,i ); 
			if(header!= null && !header.isEmpty()){
				if(isKey(header)){
					keyList.add(new Cell(i, header)); 
				}
				else{
					headerList.add(new Cell(i,header)); 
					}
				}
			}
		}
}
 
开发者ID:arago,项目名称:excel-mars-translator,代码行数:17,代码来源:NodeReader.java

示例4: readAllLines

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
public List<String[]> readAllLines(int sheetIndex){
	XSSFSheet sheet = getWorkBook().getSheetAt(sheetIndex);
	
	List<String[]> rows = CollectionFactory.newArrayList();
	for (int i = 0; i < sheet.getPhysicalNumberOfRows(); i++) {
		XSSFRow row = sheet.getRow(i);
		if (row != null) {
			String[] rowValues = new String[row.getPhysicalNumberOfCells()];
			for (int j = 0; j < row.getPhysicalNumberOfCells(); j++) {
				rowValues[j] = (row.getCell(j) != null)? getReader().read(row.getCell(j)) : "";
			}
			rows.add(rowValues);
		}
	}
	return rows;
}
 
开发者ID:lucastanziano,项目名称:JavaFX-Skeleton-DEPRECATED,代码行数:17,代码来源:XSSFileHelper.java

示例5: getValue

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的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

示例6: fromXSSFRowtoCSV

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的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

示例7: readRow

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
private Row readRow(XSSFRow poiRow, int rowNo) {
	row = new Row();

	row.setHeight((int) poiRow.getHeightInPoints());
	int firstCellNum = poiRow.getFirstCellNum();
	if (firstCellNum >= 0) {
		for (int i = 0; i < firstCellNum; i++) {
			Cell defaultCell = createDefaultCell(rowNo, i);
			row.addCell(defaultCell);
		}

		int lastCellNum = poiRow.getLastCellNum();
		for (int i = firstCellNum; i < lastCellNum; i++) {
			poiCell = poiRow.getCell(i);
			if (poiCell == null) {
				cell = createDefaultCell(rowNo, i);
			} else {
				cell = readCell(poiCell);
			}
			row.addCell(cell);
		}
	}

	return row;
}
 
开发者ID:legend0702,项目名称:excelUtils,代码行数:26,代码来源:XSSFExcelReader.java

示例8: compareTwoRows

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
public static boolean compareTwoRows(XSSFRow row1, XSSFRow row2) {
    if ((row1 == null) && (row2 == null)) {
        return true;
    } else if ((row1 == null) || (row2 == null)) {
        return false;
    }

    int firstCell1 = row1.getFirstCellNum();
    int lastCell1 = row1.getLastCellNum();
    boolean equalRows = true;

    // Compare all cells in a row
    for (int i = firstCell1; i <= lastCell1; i++) {
        XSSFCell cell1 = row1.getCell(i);
        XSSFCell cell2 = row2.getCell(i);
        if (!compareTwoCells(cell1, cell2)) {
            equalRows = false;
            break;
        }
    }
    return equalRows;
}
 
开发者ID:Talend,项目名称:data-prep,代码行数:23,代码来源:ExcelComparator.java

示例9: fillExtraFields

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
private void fillExtraFields(String tablename, Object id, XSSFRow row, LinkedHashSet<String> de, int startCol) throws SQLException {
	// ExtraFields
	if (id != null && de != null) {
		String sql = "Select * from " + MyDBI.delimitL("ExtraFields") + " WHERE " + MyDBI.delimitL("tablename") + "='" + tablename  + "' AND " + MyDBI.delimitL("id") + "=" + id;
		ResultSet rs2 = DBKernel.getResultSet(sql, false);
		if (rs2 != null && rs2.first()) {
			do {
				String s = rs2.getString("attribute");
				int j=0;
				for (String e : de) {
					if (s.equalsIgnoreCase(e)) {
						XSSFCell cell = row.getCell(startCol+j);
						if (cell == null) cell = row.createCell(startCol+j);
						cell.setCellValue(rs2.getString("value"));
						break;
					}
					j++;
				}
			} while (rs2.next());
		}	
	}		
}
 
开发者ID:SiLeBAT,项目名称:BfROpenLab,代码行数:23,代码来源:TraceGenerator.java

示例10: mappingColumn

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
@Override
public EmpVO mappingColumn(XSSFRow row) {
	XSSFCell cell0 = row.getCell(0);
   	XSSFCell cell1 = row.getCell(1);
   	XSSFCell cell2 = row.getCell(2);

	EmpVO vo = new EmpVO();

	vo.setEmpNo(new BigDecimal(cell0.getNumericCellValue()));
	vo.setEmpName(EgovExcelUtil.getValue(cell1));
	vo.setJob(EgovExcelUtil.getValue(cell2));
	
	log.debug("########### vo is " + vo.getEmpNo());
	log.debug("########### vo is " + vo.getEmpName());
	log.debug("########### vo is " + vo.getJob());
	
	return vo;
}
 
开发者ID:eGovFrame,项目名称:egovframework.rte.root,代码行数:19,代码来源:EgovPOIExcelTestMapping.java

示例11: mappingColumn

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
@Override
public ZipVO mappingColumn(XSSFRow row) {
	XSSFCell cell0 = row.getCell(0);
   	XSSFCell cell1 = row.getCell(1);
   	XSSFCell cell2 = row.getCell(2);
   	XSSFCell cell3 = row.getCell(3);
   	XSSFCell cell4 = row.getCell(4);
   	XSSFCell cell5 = row.getCell(5);
   	XSSFCell cell6 = row.getCell(6);
   	XSSFCell cell7 = row.getCell(7);

	ZipVO vo = new ZipVO();

	vo.setZipNo(new BigDecimal(cell0.getNumericCellValue()));
	vo.setSerNo(new BigDecimal(cell1.getNumericCellValue()));
	vo.setSidoNm(EgovExcelUtil.getValue(cell2));
	vo.setCggNm(EgovExcelUtil.getValue(cell3));
	vo.setUmdNm(EgovExcelUtil.getValue(cell4));
	vo.setBdNm(EgovExcelUtil.getValue(cell5));
	vo.setJibun(EgovExcelUtil.getValue(cell6));
	vo.setRegId(EgovExcelUtil.getValue(cell7));
	
	return vo;
}
 
开发者ID:eGovFrame,项目名称:egovframework.rte.root,代码行数:25,代码来源:EgovPOIExcelBigTestMapping.java

示例12: testCellDataFormat

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
/**
 * 셀 Data type 테스트
 *   셀의 값이 Null 인경우 오류발생
 */
@Test
public void testCellDataFormat() throws Exception {
	StringBuffer sb = new StringBuffer();
	sb.append(fileLocation).append("/").append("testDataFormat.xlsx");

    XSSFWorkbook wb = excelService.loadXSSFWorkbook(sb.toString());
    XSSFSheet sheet = wb.getSheetAt(0);
    
    XSSFRow row = sheet.getRow(7);
	XSSFCell cell = row.getCell(0);

	assertEquals("2009/04/01", EgovExcelUtil.getValue(cell));

	row = sheet.getRow(8);
	cell = row.getCell(0);

	assertEquals("2009/04/02", EgovExcelUtil.getValue(cell));
}
 
开发者ID:eGovFrame,项目名称:egovframework.rte.root,代码行数:23,代码来源:EgovExcelXSSFServiceTest.java

示例13: createCellIfNotPresent

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
public static XSSFCell createCellIfNotPresent(XSSFRow row, int colIndex) {
	String message = "XSSFRow must not be null!";
	Objects.requireNonNull(row, () -> message);
	XSSFCell cell = row.getCell(colIndex);
	if (Objects.isNull(cell)) {
		cell = row.createCell(colIndex);
	}
	return cell;
}
 
开发者ID:gp15237125756,项目名称:PoiExcelExport,代码行数:10,代码来源:CellValueUtil.java

示例14: createCellIfNotPresent

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
public static XSSFCell createCellIfNotPresent(XSSFRow row,int colIndex){
	String message="XSSFRow must not be null!";
	Objects.requireNonNull(row, () -> message);
	XSSFCell cell=row.getCell(colIndex);
	if(Objects.isNull(cell)){
		cell=row.createCell(colIndex);
	}
	return cell;
}
 
开发者ID:gp15237125756,项目名称:PoiExcelExport,代码行数:10,代码来源:XSSFCellUtil.java

示例15: applyStyleToRange

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
public static void applyStyleToRange(XSSFSheet sheet, XSSFCellStyle style, int rowStart, int colStart, int rowEnd, int colEnd) {
    for (int r = rowStart; r <= rowEnd; r++) {
        for (int c = colStart; c <= colEnd; c++) {
            XSSFRow row = sheet.getRow(r);

            if (row != null) {
                XSSFCell cell = row.getCell(c);

                if (cell != null) {
                    cell.setCellStyle(style);
                }
            }
        }
    }
}
 
开发者ID:lucci,项目名称:NFLFantasyAnalyzer,代码行数:16,代码来源:FileWriter.java


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