英文:
Aspose ColumnCollection getCount() exact meaning
问题
-
这里的
columns.getCount()
的值是什么意思?是指工作表中的列的最大数量吗? -
如果我想知道工作表中每行的列数,该如何在Aspose中实现?(例如,第一行有10列,第二行有5列...)
英文:
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();
- what is the value of columns.getCount() here meant? the maximum column count in a worksheet?
- if I want to know the column count of each row in a worksheet, how to do in aspose? (e.g. row1 has 10 columns, row 2 has 5 columns...)
答案1
得分: 0
1.) ColumnCollection/RowCollection.getCount()
会返回工作表中初始化的行/列数,因此它可能包括空单元格或具有null值的单元格。我认为你应该使用Cells.getMaxDataRow
和Cells.getMaxDataColumn
方法来获取最远的(最后的)行/列索引(从零开始),请参考以下示例代码段:
示例代码:
Workbook workbook = new Workbook("Book1.xlsx", new LoadOptions());
// 获取包含数据的最远(最后的)行的索引(从零开始)。
int lastRowIndex = workbook.getWorksheets().get(0).getCells().getMaxDataRow();
// 获取包含数据的最远(最后的)列的索引(从零开始)。
int lastColIndex = workbook.getWorksheets().get(0).getCells().getMaxDataColumn();
2.) 你可以使用Cells.endCellInRow
属性来获取一行中的最后一个单元格(你可以评估结果单元格的列索引)。请参考以下示例代码:
示例代码:
Worksheet worksheet = workbook.getWorksheets().get(0);
Cells cells = worksheet.getCells();
// 获取第4行中的最后一个单元格
Cell lastCellOutput = cells.endCellInRow(3);
// 获取单元格的列索引。
int col = lastCellOutput.getColumn();
希望这对你有所帮助。
关于Aspose API的详细问题,你可以在这里发帖。
英文:
1.) Well, ColumnCollection/RowCollection.getCount() would give you rows/cols count which are initialized in the worksheet, so it may include cells even if they are empty or with null values. I think you should use Cells.getMaxDataRow and Cells.getMaxDataColumn methods to get the farthest (last) row/column indices (zero-based), see the sample code segment for your reference:
e.g
Sample code:
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.) You may use Cells.endCellInRow attribute to get the last cell in a row (you may evaluate the column index of the resultant cell). See the sample code.
e.g
Sample code:
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();
Hope, this helps a bit.
For detailed questions about Aspose APIs, you may post here.
PS. I am working as Support developer/ Evangelist at Aspose.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论