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


Java XSSFSheet.getLastRowNum方法代码示例

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


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

示例1: xlsxToClassifiableTexts

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
List<ClassifiableText> xlsxToClassifiableTexts(File xlsxFile, int sheetNumber) throws IOException, EmptySheetException {
  if (xlsxFile == null ||
      sheetNumber < 1) {
    throw new IllegalArgumentException();
  }

  try (XSSFWorkbook excelFile = new XSSFWorkbook(new FileInputStream(xlsxFile))) {
    XSSFSheet sheet = excelFile.getSheetAt(sheetNumber - 1);

    // at least two rows
    if (sheet.getLastRowNum() > 0) {
      return getClassifiableTexts(sheet);
    } else {
      throw new EmptySheetException("Excel sheet (#" + sheetNumber + ") is empty");
    }
  } catch (IllegalArgumentException e) {
    throw new EmptySheetException("Excel sheet (#" + sheetNumber + ") is not found");
  }
}
 
开发者ID:RusZ,项目名称:TextClassifier,代码行数:20,代码来源:ExcelFileReader.java

示例2: getClassifiableTexts

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
private List<ClassifiableText> getClassifiableTexts(XSSFSheet sheet) {
  List<Characteristic> characteristics = getCharacteristics(sheet);
  List<ClassifiableText> classifiableTexts = new ArrayList<>();

  // start from second row
  for (int i = 1; i <= sheet.getLastRowNum(); i++) {
    Map<Characteristic, CharacteristicValue> characteristicsValues = getCharacteristicsValues(sheet.getRow(i), characteristics);

    // exclude empty rows
    if (!sheet.getRow(i).getCell(0).getStringCellValue().equals("")) {
      classifiableTexts.add(new ClassifiableText(sheet.getRow(i).getCell(0).getStringCellValue(), characteristicsValues));
    }
  }

  return classifiableTexts;
}
 
开发者ID:RusZ,项目名称:TextClassifier,代码行数:17,代码来源:ExcelFileReader.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: 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

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

示例7: readListOfNodes

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
public List<Node> readListOfNodes(final XSSFWorkbook excel, String type){
	List<Node> nodeList = new ArrayList<Node>(); 
	
	final XSSFSheet sheet = excel.getSheet(type);
	if(sheet==null)
	{
		log.error(type+" sheet not found ! ");
	}
	final int lines = sheet.getLastRowNum();
	log.info("found "+lines+" lines in '"+type+"' ");
		
		final XSSFRow firstRow = sheet.getRow(0);
		
		readHeaderFromRow(type, firstRow); 

	for(int line = 2 ;line<=lines;line++) // skip the first line two lines 
	{
		
		final XSSFRow row = sheet.getRow(line);
		
		Node node =	readNodeFromRow(type, row); 
		if(node!=null)
			nodeList.add(node);
		}
	return nodeList; 
	
}
 
开发者ID:arago,项目名称:excel-mars-translator,代码行数:28,代码来源:NodeReader.java

示例8: createTable

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
private PdfPTable createTable(PdfWriter writer, LabelFormat labelFormat, int firstRow, int lastRow) throws DocumentException {
    if(firstRow >= lastRow) {
        LOG.info("First row = " + firstRow + ", last row = " + lastRow + " so returning null");
        return null;
    }
    if(lastRow - firstRow > labelFormat.getColumns() * labelFormat.getRows()) {
        LOG.info("There were too many labels requested.  "
                + "You wanted: " + (lastRow - firstRow) + " labels, "
                + "but this label format only allows: " + labelFormat.getColumns() * labelFormat.getRows());
        return null;
    }
    final XSSFSheet sheet = xSSFWorkbook.getSheetAt(0);
    if(lastRow > sheet.getLastRowNum()) {
        LOG.info("last row was larger that the last row number of this sheet: " + sheet.getLastRowNum());
        lastRow = sheet.getLastRowNum();
    }
    if(firstRow >= lastRow) {
        LOG.info("after adjusting the last row, First row = " + firstRow + ", last row = " + lastRow + " so returning null");
        return null;
    }
    
    final PdfPTable table = new PdfPTable(labelFormat.getColumns());
    table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
    table.setWidthPercentage(labelFormat.getWidthPercentage());   
    LOG.info("The width percentage i found is; " + labelFormat.getWidthPercentage());
    for(int i = firstRow; i <= lastRow; i++) {
        LOG.info("Showing row: " + i);
        showOneLabel(sheet.getRow(i), table, writer, labelFormat);
    }
    if(lastRow == sheet.getLastRowNum()) {
        // we are at the end
        //check to make sure that the last row is filled in
        if(lastRow % labelFormat.getColumns() != 0) {
            for(int x = 0; x < lastRow % labelFormat.getColumns(); x++) {
                final PdfPCell cell = new PdfPCell();
                cell.setFixedHeight(labelFormat.getHeight() * 72);
                cell.addElement(new Paragraph("  "));
                table.addCell(cell);
            }
                
        }
    }
    return table;
}
 
开发者ID:chiralsoftware,项目名称:ExcelToBarcode,代码行数:45,代码来源:MainController.java

示例9: generatePdf

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
@RequestMapping(value = "/export.pdf")
public ResponseEntity<byte[]> generatePdf(@RequestParam Map<String,String> allRequestParams) 
        throws DocumentException {
    final LabelFormat labelFormat = allRequestParams.containsKey("labelFormatString") ?
            LabelFormat.valueOf(allRequestParams.get("labelFormatString")) :
            LabelFormat.AVERY5160;
    
    createLineTypes(allRequestParams);

    if(xSSFWorkbook == null) {
        LOG.info("The workbook is null so this wouldn't work really");
        return new ResponseEntity<>(showBlank(), HttpStatus.OK);
    }
    if(allRequestParams == null) {
        LOG.info("the allRequestParams param is null so this wouldn't work really");
        return new ResponseEntity<>(showBlank(), HttpStatus.OK);
    }
    
    // we create a new document with zero left/right margins
    // we calculate the top and bottom margin
    final float topMargin = (PageSize.LETTER.getHeight() - labelFormat.getRows() * labelFormat.getHeight() * 72) / 2;
    final Document document = new Document(PageSize.LETTER, 0,0,topMargin,topMargin);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    
    final PdfWriter writer = PdfWriter.getInstance(document, baos);
    
    document.open();
    
    final XSSFSheet sheet = xSSFWorkbook.getSheetAt(0);
    final int rowCount = sheet.getLastRowNum();
    LOG.info("With: " + rowCount + " rows, "
            + "and " + labelFormat.getRows() * labelFormat.getColumns() + " labels per page, "
            + "we need: " + (1 + rowCount / (labelFormat.getRows() * labelFormat.getColumns())) + " pages");
    for(int i = 0 ; i <=  rowCount / labelFormat.getLabelsPerPage(); i++) {
        LOG.info("Showing page: " + i);
        int firstRow = i * labelFormat.getLabelsPerPage();
        int lastRow =  firstRow + labelFormat.getLabelsPerPage();
        if(lastRow > rowCount) lastRow = rowCount;
        LOG.info("At i = " + i + ", we need to show rows " + firstRow + " to " + lastRow);
        if(lastRow > firstRow) {
            final PdfPTable t = createTable(writer, labelFormat, firstRow, lastRow);
            document.add(t);
            t.setComplete(true);
            LOG.info("i = " + i + ", added the table and adding a new page");
            document.newPage();
        }
    } 
    
    document.close();
    
    final HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setContentType(MediaType.APPLICATION_PDF);
    final ResponseEntity<byte[]> result = new ResponseEntity<>(baos.toByteArray(), 
            httpHeaders, HttpStatus.OK);
    return result;
}
 
开发者ID:chiralsoftware,项目名称:ExcelToBarcode,代码行数:57,代码来源:MainController.java

示例10: createInnerDict

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
/**
 * 创建内置字典
 *
 * @param xlsxSheet Excel 页签
 * @return 多语言翻译字典, Map<"原文", "译文">
 *
 */
private static Map<String, String> createInnerDict(XSSFSheet xlsxSheet) {
    if (xlsxSheet == null) {
        // 如果参数对象为空,
        // 则直接退出!
        return Collections.emptyMap();
    }

    // 获取总行数
    int rowNum = xlsxSheet.getLastRowNum();

    if (rowNum <= 0) {
        // 如果文件内容为空,
        // 则直接退出!
        return Collections.emptyMap();
    }

    // 创建内置字典
    Map<String, String> innerDict = new HashMap<>();

    for (int i = 1; i <= rowNum; i++) {
        // 获取一行数据
        XSSFRow xlsxRow = xlsxSheet.getRow(i);

        // 获取原文和译文,
        // A 列 = 原文, B 列 = 译文
        String origStr = XSSFUtil.getStrCellVal(xlsxRow.getCell(0));
        String langStr = XSSFUtil.getStrCellVal(xlsxRow.getCell(1));

        if (origStr == null ||
            origStr.isEmpty() ||
            langStr == null ||
            langStr.isEmpty()) {
            continue;
        }

        // 将原文译文添加到字典
        innerDict.put(origStr, langStr);
    }

    return innerDict;
}
 
开发者ID:hjj2017,项目名称:xgame-code_server,代码行数:49,代码来源:XlsxMultiLang.java


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