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


Java XSSFSheet.getRow方法代码示例

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


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

示例1: readXlsx

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
public static ArrayList readXlsx(String path) throws IOException {
    XSSFWorkbook xwb = new XSSFWorkbook(path);
    XSSFSheet sheet = xwb.getSheetAt(0);
    XSSFRow row;
    String[] cell = new String[sheet.getPhysicalNumberOfRows() + 1];
    ArrayList<String> arrayList = new ArrayList<>();
    for (int i = sheet.getFirstRowNum() + 1; i < sheet.getPhysicalNumberOfRows(); i++) {
        cell[i] = "";
        row = sheet.getRow(i);
        for (int j = row.getFirstCellNum(); j < row.getPhysicalNumberOfCells(); j++) {
            cell[i] += row.getCell(j).toString();
            cell[i] += " | ";
        }
        arrayList.add(cell[i]);
    }
    return arrayList;
}
 
开发者ID:inkss,项目名称:hotelbook-JavaWeb,代码行数:18,代码来源:ExportExcel.java

示例2: getReferenceList

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
private List<Object> getReferenceList(XSSFSheet sheet, DataValidationConstraint validationConstraint) {
	List<Object> references = new LinkedList<>();

	AreaReference areaRef = new AreaReference(validationConstraint.getFormula1());
	CellReference[] cellRefs = areaRef.getAllReferencedCells();
	for (CellReference cellRef : cellRefs) {
		XSSFSheet referenceListSheet;
		if (cellRef.getSheetName() != null) {
			referenceListSheet = sheet.getWorkbook().getSheet(cellRef.getSheetName());
		} else {
			referenceListSheet = sheet;
		}
		Row row = referenceListSheet.getRow(cellRef.getRow());
		if (row != null) {
			Cell cell = row.getCell(cellRef.getCol());
			if (cell != null) {
				Object cellValue = CellValueParser.getCellValue(cell);
				references.add(cellValue);
			}
		}
	}
	return references;
}
 
开发者ID:ykaragol,项目名称:poi-data-validation,代码行数:24,代码来源:DataValidator.java

示例3: copySheets

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
/**
 * @param newSheet the sheet to create from the copy.
 * @param sheet the sheet to copy.
 * @param copyStyle true copy the style.
 */
public static void copySheets(XSSFSheet newSheet, XSSFSheet sheet, boolean copyStyle) {
    int maxColumnNum = 0;
    Map<Integer, XSSFCellStyle> styleMap = (copyStyle) ? new HashMap<Integer, XSSFCellStyle>() : null;
    for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
        XSSFRow srcRow = sheet.getRow(i);
        XSSFRow destRow = newSheet.createRow(i);
        if (srcRow != null) {
            Util.copyRow(sheet, newSheet, srcRow, destRow, styleMap);
            if (srcRow.getLastCellNum() > maxColumnNum) {
                maxColumnNum = srcRow.getLastCellNum();
            }
        }
    }
    for (int i = 0; i <= maxColumnNum; i++) {
        newSheet.setColumnWidth(i, sheet.getColumnWidth(i));
    }
   //Util.copyPictures(newSheet,sheet) ;
}
 
开发者ID:likelet,项目名称:DAtools,代码行数:24,代码来源:Util.java

示例4: readXlsx

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

示例5: readAllLines

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

示例6: getCell

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
/**
 * Returns the cell of a given sheet at icol;irow. Former values are overwritten.
 *
 * @param sheet the sheet to write on
 * @param icol index of column
 * @param irow index of row
 * @return the given cell at icol;irow
 * @see
 */
public Cell getCell(XSSFSheet sheet, int icol, int irow) {
  // try to get row
  Row row = sheet.getRow(irow);
  // if not exist: create row
  if (row == null)
    row = sheet.createRow(irow);
  // get cell
  return row.createCell(icol);
}
 
开发者ID:mzmine,项目名称:mzmine2,代码行数:19,代码来源:XSSFExcelWriterReader.java

示例7: getValue

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

示例8: setCell

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
/**
 * @param sheet 
 * @param pos 位置【row,col】
 * @param style
 * @param v
 */
public static void setCell(final XSSFWorkbook wb,final XSSFSheet sheet,int[] pos,CellStyle style,FontStyle font,String v){
	XSSFRow row = sheet.getRow(pos[0]);
	XSSFCell cell = CellValueUtil.createCellIfNotPresent(row, pos[1]);
	XSSFCellStyle _style = Objects
			.requireNonNull(new XSSFCellStyleLib(wb).get(style),
					"specified style not defined!");
	XSSFFont _font = Objects
			.requireNonNull(new XSSFFontStyleLib(wb).get(font),
					"specified font not defined!");
	_style.setFont(_font);
	setCellProperties(cell, v, _style);
}
 
开发者ID:gp15237125756,项目名称:PoiExcelExport,代码行数:19,代码来源:CellValueUtil.java

示例9: setRowMutipleColContent

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
/**
 * 设置单行全部内容
 * @param sheet
 * @param wb
 * @param rowNum
 * @param kVal
 */
public static void setRowMutipleColContent(XSSFSheet sheet,XSSFWorkbook wb,int rowNum,final Map<Integer,String> kVal){
	String message="XSSFSheet must not be null!";
	Objects.requireNonNull(sheet, () -> message);
	XSSFRow row=sheet.getRow(rowNum);
	if(!kVal.isEmpty()){
		kVal.forEach((k,v)->{
			setRowContents(row,k,v,wb);
		});
	}
	
}
 
开发者ID:gp15237125756,项目名称:PoiExcelExport,代码行数:19,代码来源:XSSFCellUtil.java

示例10: applyStyleToRange

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

示例11: buildMaxColumn

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
private int buildMaxColumn(XSSFSheet sheet){
	int rowCount=sheet.getPhysicalNumberOfRows();
	int maxColumnCount=0;
	for(int i=0;i<rowCount;i++){
		XSSFRow row=sheet.getRow(i);
		if(row==null){
			continue;
		}
		int columnCount=row.getPhysicalNumberOfCells();
		if(columnCount>maxColumnCount){
			maxColumnCount=columnCount;
		}
	}
	return maxColumnCount;
}
 
开发者ID:youseries,项目名称:ureport,代码行数:16,代码来源:XSSFExcelParser.java

示例12: copySheets2CSV

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
public static void copySheets2CSV(XSSFSheet sheet, String csvfile) {
        int maxColumnNum = 0;
        Map<Integer, XSSFCellStyle> styleMap = null;

        try {
            FileWriter fw = new FileWriter(csvfile);

            String str = "";
            for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
                XSSFRow srcRow = sheet.getRow(i);
                if (srcRow != null) {
                    System.out.println(srcRow.getLastCellNum());
                    System.out.println(srcRow.getFirstCellNum());
//                    System.out.println(srcRow.getCell(srcRow.getLastCellNum()).toString());
                    for (int j = srcRow.getFirstCellNum(); j < srcRow.getLastCellNum(); j++) {
                        
                        if (srcRow.getCell(j)!=null&&j != srcRow.getLastCellNum()-1) {
                            srcRow.getCell(j).setCellType(1);
                            
                            str = str +srcRow.getCell(j).getReference()+ ",";
                        } else if(srcRow.getCell(j)!=null){
                            srcRow.getCell(j).setCellType(1);
                            
                            str = str +srcRow.getCell(j).getStringCellValue()+ "\r\n";
                        }
//
                    }
                    fw.append(str);
                }
                str = "";
            }

            fw.flush();
            fw.close();
        } catch (IOException ex) {

        }//Util.copyPictures(newSheet,sheet) ;
    }
 
开发者ID:likelet,项目名称:DAtools,代码行数:39,代码来源:Excel2csv.java

示例13: extractDataFromXls

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
private static JSONArray extractDataFromXls(XSSFWorkbook wb) {
    XSSFSheet sheet = wb.getSheetAt(0);

    int rows = sheet.getPhysicalNumberOfRows();
    int cols = sheet.getRow(0).getPhysicalNumberOfCells();
    int startRow = 1; // Pular cabecalho.

    JsonObjectCreator jsonObjCreator = new FedDepJsonObjectCreator();
    JSONArray jArr = new JSONArray();
    for(int row = startRow; row < rows; row++) {
        XSSFRow xssfRow = sheet.getRow(row);
        if(xssfRow != null) {

            String[] rowData = new String[cols];
            for(int col = 0; col < cols; col++) {
                XSSFCell cell = xssfRow.getCell(col);
                if(cell != null) {
                    String datum;
                    if (XSSFCell.CELL_TYPE_STRING == cell.getCellType()) {
                        datum = cell.getStringCellValue();
                    }
                    else if (XSSFCell.CELL_TYPE_NUMERIC == cell.getCellType()) {
                        datum = String.valueOf(cell.getNumericCellValue());
                    }
                    else {
                        System.out.println("A célula: [" + row + "," + col + "] não contém um String e nem um Número.");
                        datum = "";
                    }

                    rowData[col] = datum;
                }
            }

            JSONObject jObj = jsonObjCreator.processLine(rowData);
            jArr.add(jObj);
        }
    }

    return jArr;
}
 
开发者ID:TekkLabs,项目名称:memoria-politica,代码行数:41,代码来源:FedDepXlsxConverter.java

示例14: dataProvider

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
/**
 * Opens the xlsx file based on the filename and sheet passed in.
 * Creates the 2 dimension array filled with the data.
 *
 * @param fname     - File name (relative path from resources directory)
 * @param sheetName - Sheet name within the excel file.
 * @return Object[][] 2 dimensional array with data from the xlsx file
 */
public static String[][] dataProvider(String fname, String sheetName) {
    try {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        String fileName = Paths.get(classLoader.getResource(fname).toURI()).toString();
        //log.info("Filename to be loaded: " + fileName);

        File xlsFile = new File(fileName);
        FileInputStream file = new FileInputStream(xlsFile);
        XSSFWorkbook workbook = new XSSFWorkbook(file);
        XSSFSheet sheet = workbook.getSheet(sheetName);
        int rowCount = sheet.getLastRowNum() + 1;
        int colCount = sheet.getRow(0).getLastCellNum();

        //log.info("Rows: " + rowCount + " Columns: " + colCount);

        String[][] retval = new String[rowCount - 1][colCount];

        for (int i = 1; i < rowCount; i++) {
            XSSFRow row = sheet.getRow(i);
            for (int j = 0; j < colCount; j++) {
                //System.out.print(row.getCell(j) + "\t\t");
                retval[i - 1][j] = row.getCell(j).toString().trim();
            }
            //System.out.println();
        }
        return retval;

    } catch (Exception ex) {
        log.error("Error occurred while loading excel file: " + ex.toString());
        return null;
    }
}
 
开发者ID:Rhoynar,项目名称:qa-automation,代码行数:41,代码来源:ExcelUtils.java

示例15: writeToSheet

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
public void writeToSheet(String sheetName, Map<Integer,String> cellValues, Map<Integer,String> headerValues){
	XSSFSheet sheet; 
	if(sheetNames.contains(sheetName)){
		sheet = wb.getSheet(sheetName); 
		}
	else{
		sheet = wb.createSheet(sheetName); 
		sheetNames.add(sheetName); 
		}
	setRowNumber(headerValues);
	
	
	XSSFRow row = sheet.createRow(lastRow); 
	
	for(int i : cellValues.keySet()){
		XSSFCell cell = row.createCell(i); 
		cell.setCellValue(cellValues.get(i));
	}
	
	
	XSSFRow headerRow = sheet.getRow(0);
	if(headerRow == null); 
		headerRow = sheet.createRow(0); 
	
	for(int j : headerValues.keySet()){
		XSSFCell headerCell = headerRow.createCell(j); 
		headerCell.setCellValue(headerValues.get(j));
	}

	incRowNumber(headerValues);
}
 
开发者ID:arago,项目名称:excel-mars-translator,代码行数:32,代码来源:ExcelWriter.java


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