【问题标题】:Aspose ColumnCollection getCount() exact meaningAspose ColumnCollection getCount() 确切含义
【发布时间】:2020-08-11 10:33:36
【问题描述】:

假设

    //Instantiating a Workbook object
    Workbook workbook = new Workbook();        
    //Obtaining the reference of the first worksheet
    Worksheet worksheet = workbook.getWorksheets().get(0);
    ColumnCollection columns = worksheet.getCells().getColumns();
    int count = columns.getCount();
  1. 这里的columns.getCount()的值是什么意思?工作表中的最大列数?
  2. 如果我想知道工作表中每一行的列数,aspose 怎么办? (例如,第 1 行有 10 列,第 2 行有 5 列...)

【问题讨论】:

    标签: java excel aspose


    【解决方案1】:

    1.) 那么,ColumnCollection/RowCollection.getCount() 会为您提供在工作表中初始化的行数/列数,因此即使单元格为空或具有空值,它也可能包含单元格。我认为您应该使用 Cells.getMaxDataRow 和 Cells.getMaxDataColumn 方法来获取最远(最后)行/列索引(从零开始),请参阅示例代码段以供参考: 例如

    示例代码:

    Workbook workbook = new Workbook("Book1.xlsx", new LoadOptions());
    //Get the farthest (last) row's index (zero-based) which contains data.
    int lastRowIndex = workbook.getWorksheets().get(0).getCells().getMaxDataRow();
    //Get the farthest (last) column's index (zero-based) which contains data.
    int lastColIndex = workbook.getWorksheets().get(0).getCells().getMaxDataColumn();
    

    2.) 您可以使用 Cells.endCellInRow 属性来获取一行中的最后一个单元格(您可以评估结果单元格的列索引)。请参阅示例代码。 例如

    示例代码:

    Worksheet worksheet = workbook.getWorksheets().get(0);
    Cells cells = worksheet.getCells();     
    //Get last cell in the 4th row
    Cell lastCellOutput = cells.endCellInRow(3);
    //Get the column index of the cell.
    int col = lastCellOutput.getColumn();
    

    希望,这有点帮助。

    有关 Aspose API 的详细问题,您可以在这里post

    PS。我在 Aspose 担任支持开发人员/布道者。

    【讨论】:

      猜你喜欢
      • 2019-05-12
      • 1970-01-01
      • 1970-01-01
      • 2021-06-13
      • 1970-01-01
      • 2011-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多