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

x33g5p2x  于2022-01-28 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(192)

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

Row.getPhysicalNumberOfCells介绍

[英]Gets the number of defined cells (NOT number of cells in the actual row!). That is to say if only columns 0,4,5 have values then there would be 3.
[中]获取定义的单元格数(不是实际行中的单元格数!)。也就是说,如果只有0,4,5列有值,那么就有3列。

代码示例

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

if (maxColumnWidths.size() < row.getPhysicalNumberOfCells()) {

代码示例来源:origin: kiegroup/optaplanner

assertCellConstant(headerRow.getCell(5), "Standard deviation");
int assetClassListSize = headerRow.getPhysicalNumberOfCells() - ASSET_CLASS_PROPERTIES_COUNT;
List<AssetClass> assetClassList = new ArrayList<>(assetClassListSize);
Map<Long, AssetClass> idToAssetClassMap = new HashMap<>(assetClassListSize);
    continue;
  if (row.getPhysicalNumberOfCells() != (ASSET_CLASS_PROPERTIES_COUNT + assetClassListSize)) {
    throw new IllegalArgumentException("The row (" + row.getRowNum() + ") has "
        + row.getPhysicalNumberOfCells() + " cells, but is expected to have "
        + (ASSET_CLASS_PROPERTIES_COUNT + assetClassListSize) + " cells instead.");

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

private String[] readRow(int index) {
    Row row = sheet.getRow(index);
    if (row == null || row.getPhysicalNumberOfCells() == 0) {
      return new String[0];
    }

    String[] record = new String[row.getLastCellNum()];
    for (int i = 0; i < record.length; i++) {
      record[i] =  Optional.ofNullable(row.getCell(i)).map(Object::toString).orElse(null);
    }
    return record;
  }
}

代码示例来源:origin: lcw2004/one

/**
   * 将文档设置为按指定行自适应大小
   *
   * @param sheet  sheet
   * @param rowNum 行号
   */
  public static void autoSize(Sheet sheet, int rowNum) {
    Row row = sheet.getRow(rowNum);
    if (row != null) {
      for (int i = 0; i < row.getPhysicalNumberOfCells(); i++) {
        sheet.autoSizeColumn(i, true);
//                if (sheet.getColumnWidth(i) == 0) {
//                    sheet.setColumnWidth(i, 100);
//                }
      }
    }
  }

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

private void compareDataInRow(Locator loc1, Locator loc2) {
  for (int k = 0; k < loc1.row.getLastCellNum(); k++) {
    if (loc2.row.getPhysicalNumberOfCells() <= k) return;
    loc1.cell = loc1.row.getCell(k);
    loc2.cell = loc2.row.getCell(k);
    if ((loc1.cell == null) || (loc2.cell == null)) {
      continue;
    }
    compareDataInCell(loc1, loc2);
  }
}

代码示例来源:origin: metatron-app/metatron-discovery

private void createHeaderRow(Sheet sheet) {
 sheet.shiftRows(0, sheet.getLastRowNum(), 1);
 Row row = sheet.createRow(0);
 for (int i = 0; i < sheet.getRow(1).getPhysicalNumberOfCells(); i++) {
  Cell cell = row.createCell(i);
  cell.setCellValue("field_" + (i + 1));
 }
}

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

for (Iterator<Row> rit = sheet.rowIterator(); rit.hasNext();) {
     Row row = rit.next();
     String[] cells = new String[row.getPhysicalNumberOfCells()];
     int i = 0;
     for (Iterator<Cell> cit = row.cellIterator(); cit.hasNext();) {
       Cell cell = cit.next();
       cell.setCellType(Cell.CELL_TYPE_STRING);
       cells[i++] = cell.getStringCellValue();
     }
     // At this point you can put the values of the cells in
     // your map entry.
     System.out.println(Arrays.toString(cells);
   }

代码示例来源:origin: cpesch/RouteConverter

private ColumnTypeToRowIndexMapping parseHeader(Row row) {
  ColumnTypeToRowIndexMapping result = new ColumnTypeToRowIndexMapping();
  for (int i = 0, c = row.getPhysicalNumberOfCells(); i < c; i++) {
    Cell cell = row.getCell(i);
    String cellValue = cell.getStringCellValue();
    ColumnType columnType = parseColumnType(cellValue);
    log.info(format("Column %d with name '%s' is identified as %s", i, cellValue, columnType));
    result.add(i, columnType);
  }
  return result;
}

代码示例来源:origin: com.github.mg365/mg-common

for (int j = 0; j < row_.getPhysicalNumberOfCells(); j++) {
  Cell cell = row_.getCell(j);
  header.put(j, cell.getStringCellValue());
  for (int j = 0; j < row_.getPhysicalNumberOfCells(); j++) {

代码示例来源:origin: torakiki/sejda

for (int c = 0; c < sheet.getRow(0).getPhysicalNumberOfCells(); c++) {
  sheet.autoSizeColumn(c);

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

/**
 * Compare number of columns in sheets.
 */
private void compareNumberOfColumnsInSheets(Locator loc1, Locator loc2) {
  for (int i = 0; i < loc1.workbook.getNumberOfSheets(); i++) {
    if (loc2.workbook.getNumberOfSheets() <= i) return;
    
    loc1.sheet = loc1.workbook.getSheetAt(i);
    loc2.sheet = loc2.workbook.getSheetAt(i);
    Iterator<Row> ri1 = loc1.sheet.rowIterator();
    Iterator<Row> ri2 = loc2.sheet.rowIterator();
    
    int num1 = (ri1.hasNext()) ? ri1.next().getPhysicalNumberOfCells() : 0;
    int num2 = (ri2.hasNext()) ? ri2.next().getPhysicalNumberOfCells() : 0;
    
    if (num1 != num2) {
      String str = String.format(Locale.ROOT, "%s\nworkbook1 -> %s [%d] != workbook2 -> %s [%d]",
        "Number Of Columns does not Match ::",
        loc1.sheet.getSheetName(), num1,
        loc2.sheet.getSheetName(), num2
      );
      listOfDifferences.add(str);
    }
  }
}

代码示例来源:origin: org.sejda/sejda-sambox

for (int c = 0; c < sheet.getRow(0).getPhysicalNumberOfCells(); c++) {
  sheet.autoSizeColumn(c);

代码示例来源:origin: cpesch/RouteConverter

private void parseSheet(Sheet sheet, ParserContext<ExcelRoute> context) {
  if (sheet.getPhysicalNumberOfRows() < 2)
    return;
  Row header = sheet.getRow(0);
  log.info(format("Parsing sheet '%s' with %d rows and %d columns", sheet.getSheetName(), sheet.getPhysicalNumberOfRows(), header.getPhysicalNumberOfCells()));
  ColumnTypeToRowIndexMapping mapping = parseHeader(header);
  List<ExcelPosition> positions = new ArrayList<>();
  for (int i = 1, c = sheet.getPhysicalNumberOfRows(); i < c; i++) {
    Row row = sheet.getRow(i);
    // in case there is just a formatting in a line, the row is null
    if (row != null)
      positions.add(new ExcelPosition(row, mapping));
  }
  context.appendRoute(new ExcelRoute(this, sheet, mapping, positions));
}

代码示例来源:origin: com.blackducksoftware.tools/common-framework

for (int i = 0; i < headerRow.getPhysicalNumberOfCells(); i++) {
  Cell headerCell = headerRow.getCell(i);
  if (headerCell == null) {

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

if (maxColumnWidths.size() < row.getPhysicalNumberOfCells()) {

代码示例来源:origin: licc168/admin-api

/**
 *
 * 解析excel表格头信息
 * @throws IOException
 */
public   String[] paseExcelHead(String sheetName, InputStream input) throws Exception {
  Workbook workbook = create(input);
  Sheet sheet = workbook.getSheet(sheetName);
  if (!sheetName.trim().equals("")) {
    sheet = workbook.getSheet(sheetName);// 如果指定sheet名,则取指定sheet中的内容.
  }
  if (sheet == null) {
    sheet = workbook.getSheetAt(0); // 如果传入的sheet名不存在则默认指向第1个sheet.
  }
  Row row = sheet.getRow(0);
  int cells = row.getPhysicalNumberOfCells();
  String[] excelHead = new String[cells];
  for (int j = 0; j < cells; j++) {
    Cell cell = row.getCell(j);
    String c = parseExcel(cell, 0);
    excelHead[j] = c;
  }
  return excelHead;
}

代码示例来源:origin: Adobe-Consulting-Services/acs-aem-commons

Cell headerCell = headerRow.createCell(headerRow.getPhysicalNumberOfCells());
headerCell.setCellValue(columnName);
headerCell.setCellStyle(headerStyle);

代码示例来源:origin: QihooTest/Leo

/**
   * 获取总列数
   * @return int
   */
  public int getColNum() {
    int max=0;
    if (null==getSheet())return 0;
    if (getSheet().getPhysicalNumberOfRows()<1)return 0;
    for (int i = 0; i < getRowNum(); i++) {
      int tmp=getRow(i).getPhysicalNumberOfCells();
//            log.error(i+"=="+tmp);
      if (tmp>=max)max=tmp;
    }
    return max;
  }

代码示例来源:origin: andruhon/AndroidReadXLSX

public void onReadClick(View view) {
  printlnToUser("reading XLSX file from resources");
  InputStream stream = getResources().openRawResource(R.raw.test1);
  try {
    XSSFWorkbook workbook = new XSSFWorkbook(stream);
    XSSFSheet sheet = workbook.getSheetAt(0);
    int rowsCount = sheet.getPhysicalNumberOfRows();
    FormulaEvaluator formulaEvaluator = workbook.getCreationHelper().createFormulaEvaluator();
    for (int r = 0; r<rowsCount; r++) {
      Row row = sheet.getRow(r);
      int cellsCount = row.getPhysicalNumberOfCells();
      for (int c = 0; c<cellsCount; c++) {
        String value = getCellAsString(row, c, formulaEvaluator);
        String cellInfo = "r:"+r+"; c:"+c+"; v:"+value;
        printlnToUser(cellInfo);
      }
    }
  } catch (Exception e) {
    /* proper exception handling to be here */
    printlnToUser(e.toString());
  }
}

代码示例来源:origin: hs-web/hsweb-expands

if (rowNum <= 0) continue;
Row row = sheet.getRow(0);
int colNum = row.getPhysicalNumberOfCells();
for (int i = 0; i <= rowNum; i++) {
  row = sheet.getRow(i);

相关文章