Aspose ColumnCollection getCount() 确切含义

Aspose ColumnCollection getCount() exact meaning

Aspose

    //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 列...)

1.) 那么,ColumnCollection/RowCollection.getCount() 会给你 rows/cols 工作表中初始化的计数,因此它可能包括单元格,即使它们是空的或空值。我认为你应该使用 Cells.getMaxDataRow 和 Cells.getMaxDataColumn 方法来获取最远的(最后) row/column 索引(zero-based),请参阅示例代码段以供参考: 例如

示例代码:

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 担任支持开发人员/传播者。