org.apache.poi.ss.usermodel.Sheet.getLastRowNum()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(451)

本文整理了Java中org.apache.poi.ss.usermodel.Sheet.getLastRowNum()方法的一些代码示例,展示了Sheet.getLastRowNum()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Sheet.getLastRowNum()方法的具体详情如下:
包路径:org.apache.poi.ss.usermodel.Sheet
类名称:Sheet
方法名:getLastRowNum

Sheet.getLastRowNum介绍

[英]Gets the last row on the sheet Note: rows which had content before and were set to empty later might still be counted as rows by Excel and Apache POI, so the result of this method will include such rows and thus the returned value might be higher than expected!
[中]获取工作表上的最后一行注意:Excel和Apache POI可能仍会将以前有内容但后来设置为空的行计为行,因此此方法的结果将包括这些行,因此返回的值可能高于预期!

代码示例

代码示例来源:origin: pentaho/pentaho-kettle

public int getRows() {
 return sheet.getLastRowNum() + 1;
}

代码示例来源:origin: looly/hutool

/**
 * 
 * sheet是否为空
 * 
 * @param sheet {@link Sheet}
 * @return sheet是否为空
 * @since 4.0.1
 */
public static boolean isEmpty(Sheet sheet) {
  return null == sheet || (sheet.getLastRowNum() == 0 && sheet.getPhysicalNumberOfRows() == 0);
}

代码示例来源:origin: looly/hutool

/**
 * 
 * sheet是否为空
 * 
 * @param sheet {@link Sheet}
 * @return sheet是否为空
 * @since 4.0.1
 */
public static boolean isEmpty(Sheet sheet) {
  return null == sheet || (sheet.getLastRowNum() == 0 && sheet.getPhysicalNumberOfRows() == 0);
}

代码示例来源:origin: pentaho/pentaho-kettle

private void openLine() {
 if ( data.shiftExistingCells ) {
  data.sheet.shiftRows( data.posY, Math.max( data.posY, data.sheet.getLastRowNum() ), 1 );
 }
}

代码示例来源:origin: stackoverflow.com

Workbook wb3=WorkbookFactory.create(new FileInputStream("Book1.xls"));
 Sheet sh=wb3.getSheet("sheet1");  
 int rows=sh.getLastRowNum();

代码示例来源:origin: org.apache.poi/poi

/**
 * Compute width of a column and return the result
 *
 * @param sheet the sheet to calculate
 * @param column    0-based index of the column
 * @param useMergedCells    whether to use merged cells
 * @return  the width in pixels or -1 if all cells are empty
 */
public static double getColumnWidth(Sheet sheet, int column, boolean useMergedCells) {
  return getColumnWidth(sheet, column, useMergedCells, sheet.getFirstRowNum(), sheet.getLastRowNum());
}

代码示例来源:origin: pentaho/pentaho-kettle

public KCell[] getRow( int rownr ) {
 if ( rownr < sheet.getFirstRowNum() ) {
  return new KCell[] {};
 } else if ( rownr > sheet.getLastRowNum() ) {
  throw new ArrayIndexOutOfBoundsException( "Read beyond last row: " + rownr );
 }
 Row row = sheet.getRow( rownr );
 if ( row == null ) { // read an empty row
  return new KCell[] {};
 }
 int cols = row.getLastCellNum();
 if ( cols < 0 ) { // this happens if a row has no cells, POI returns -1 then
  return new KCell[] {};
 }
 PoiCell[] xlsCells = new PoiCell[cols];
 for ( int i = 0; i < cols; i++ ) {
  Cell cell = row.getCell( i );
  if ( cell != null ) {
   xlsCells[i] = new PoiCell( cell );
  }
 }
 return xlsCells;
}

代码示例来源:origin: looly/hutool

endRowIndex = Math.min(endRowIndex, this.sheet.getLastRowNum());// 读取结束行(包含)
boolean isFirstLine = true;
List rowList;

代码示例来源:origin: looly/hutool

endRowIndex = Math.min(endRowIndex, this.sheet.getLastRowNum());// 读取结束行(包含)
boolean isFirstLine = true;
List rowList;

代码示例来源:origin: alibaba/easyexcel

@Override
public void addContent(List data, int startRow) {
  if (CollectionUtils.isEmpty(data)) {
    return;
  }
  int rowNum = context.getCurrentSheet().getLastRowNum();
  if (rowNum == 0) {
    Row row = context.getCurrentSheet().getRow(0);
    if (row == null) {
      if (context.getExcelHeadProperty() == null || !context.needHead()) {
        rowNum = -1;
      }
    }
  }
  if (rowNum < startRow) {
    rowNum = startRow;
  }
  for (int i = 0; i < data.size(); i++) {
    int n = i + rowNum + 1;
    addOneRowOfDataToExcel(data.get(i), n);
  }
}

代码示例来源:origin: looly/hutool

final int lastRowNum = sheet.getLastRowNum();
if (headerRowIndex < firstRowNum) {
  throw new IndexOutOfBoundsException(StrUtil.format("Header row index {} is lower than first row index {}.", headerRowIndex, firstRowNum));

代码示例来源:origin: looly/hutool

final int lastRowNum = sheet.getLastRowNum();
if (headerRowIndex < firstRowNum) {
  throw new IndexOutOfBoundsException(StrUtil.format("Header row index {} is lower than first row index {}.", headerRowIndex, firstRowNum));

代码示例来源:origin: primefaces/primefaces

@Override
protected void exportCells(DataTable table, Object document) {
  Sheet sheet = (Sheet) document;
  int sheetRowIndex = sheet.getLastRowNum() + 1;
  Row row = sheet.createRow(sheetRowIndex);
  for (UIColumn col : table.getColumns()) {
    if (col instanceof DynamicColumn) {
      ((DynamicColumn) col).applyStatelessModel();
    }
    if (col.isRendered() && col.isExportable()) {
      addColumnValue(row, col.getChildren(), col);
    }
  }
}

代码示例来源:origin: alibaba/easyexcel

public void initTableHead() {
  if (needHead && null != excelHeadProperty && !CollectionUtils.isEmpty(excelHeadProperty.getHead())) {
    int startRow = currentSheet.getLastRowNum();
    if (startRow > 0) {
      startRow += 4;
    } else {
      startRow = currentSheetParam.getStartRow();
    }
    addMergedRegionToCurrentSheet(startRow);
    int i = startRow;
    for (; i < this.excelHeadProperty.getRowNum() + startRow; i++) {
      Row row = WorkBookUtil.createRow(currentSheet, i);
      if (null != afterWriteHandler) {
        this.afterWriteHandler.row(i, row);
      }
      addOneRowOfHeadDataToExcel(row, this.excelHeadProperty.getHeadByRowNum(i - startRow));
    }
  }
}

代码示例来源:origin: zstackio/zstack

@Override
public String[] nextRecord() {
  if (readingRowIndex == sheet.getLastRowNum()) {
    return null;
  }
  return readRow(++readingRowIndex);
}

代码示例来源:origin: primefaces/primefaces

protected void addColumnFacets(DataTable table, Sheet sheet, Exporter.ColumnType columnType) {
  int sheetRowIndex = columnType.equals(Exporter.ColumnType.HEADER) ? 0 : (sheet.getLastRowNum() + 1);
  Row rowHeader = sheet.createRow(sheetRowIndex);

代码示例来源:origin: pentaho/pentaho-kettle

data.posY = 0;
if ( data.sheet.getPhysicalNumberOfRows() > 0 ) {
 data.posY = data.sheet.getLastRowNum();
 data.posY++;
int currentRowNum = templateSheet.getLastRowNum();
SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook( (XSSFWorkbook) data.wb, 100 );
Sheet aNewSheet = sxssfWorkbook.getSheet( data.realSheetname );
int aNewSheetRowCount = aNewSheet.getLastRowNum();
while ( currentRowNum > aNewSheetRowCount ) {
 templateSheet.removeRow( templateSheet.getRow( currentRowNum ) );

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

public XLSSpliterator(Sheet sheet, Selection selection, String[] header, String url, long skip, long limit, boolean ignore, Map<String, Mapping> mapping, List<Object> nullValues) throws IOException {
  super(Long.MAX_VALUE, Spliterator.ORDERED);
  this.sheet = sheet;
  this.selection = selection;
  this.header = header;
  this.url = url;
  this.ignore = ignore;
  this.mapping = mapping;
  this.nullValues = nullValues;
  int headerOffset = header != null ? 1 : 0;
  this.skip = skip + selection.getOrDefault(selection.top, sheet.getFirstRowNum()) + headerOffset;
  this.limit = limit == Long.MAX_VALUE ? selection.getOrDefault(selection.bottom, sheet.getLastRowNum()) : skip + limit;
  lineNo = this.skip;
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Procedure("apoc.load.xls")
@Description("apoc.load.xls('url','selector',{config}) YIELD lineNo, list, map - load XLS fom URL as stream of row values,\n config contains any of: {skip:1,limit:5,header:false,ignore:['tmp'],arraySep:';',mapping:{years:{type:'int',arraySep:'-',array:false,name:'age',ignore:false, dateFormat:'iso_date', dateParse:['dd-MM-yyyy']}}")
public Stream<XLSResult> xls(@Name("url") String url, @Name("selector") String selector, @Name(value = "config",defaultValue = "{}") Map<String, Object> config) {
  boolean failOnError = booleanValue(config, "failOnError", true);
  try (CountingInputStream stream = FileUtils.inputStreamFor(url)) {
    Selection selection = new Selection(selector);
    char arraySep = separator(config, "arraySep", DEFAULT_ARRAY_SEP);
    long skip = longValue(config, "skip", 0L);
    boolean hasHeader = booleanValue(config, "header", true);
    long limit = longValue(config, "limit", Long.MAX_VALUE);
    List<String> ignore = value(config, "ignore", emptyList());
    List<Object> nullValues = value(config, "nullValues", emptyList());
    Map<String, Map<String, Object>> mapping = value(config, "mapping", Collections.emptyMap());
    Map<String, Mapping> mappings = createMapping(mapping, arraySep, ignore);
    Workbook workbook = WorkbookFactory.create(stream);
    Sheet sheet = workbook.getSheet(selection.sheet);
    if (sheet==null) throw new IllegalStateException("Sheet "+selection.sheet+" not found");
    selection.updateVertical(sheet.getFirstRowNum(),sheet.getLastRowNum());
    Row firstRow = sheet.getRow(selection.top);
    selection.updateHorizontal(firstRow.getFirstCellNum(), firstRow.getLastCellNum());
    String[] header = getHeader(hasHeader, firstRow,selection, ignore, mappings);
    boolean checkIgnore = !ignore.isEmpty() || mappings.values().stream().anyMatch( m -> m.ignore);
    return StreamSupport.stream(new XLSSpliterator(sheet, selection, header, url, skip, limit, checkIgnore,mappings, nullValues), false);
  } catch (Exception e) {
    if(!failOnError)
      return Stream.of(new  XLSResult(new String[0], new Object[0], 0, true, Collections.emptyMap(), emptyList()));
    else
      throw new RuntimeException("Can't read XLS from URL " + cleanUrl(url), e);
  }
}

代码示例来源:origin: qaprosoft/carina

private static List<String> getLocatorKeys(Sheet sheet) {
  List<String> locatorKeys = new ArrayList<String>();
  int lastRow = sheet.getLastRowNum();
  for (int i = 1; i <= lastRow; i++) {
    locatorKeys.add(getCellValue(sheet.getRow(i).getCell(0)));
  }
  return locatorKeys;
}

相关文章

微信公众号

最新文章

更多