java - Aspose ColumnCollection getCount() 确切含义
问题描述
假设
//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();
- columns.getCount() 这里的值是什么意思?工作表中的最大列数?
- 如果我想知道工作表中每一行的列数,怎么办?(例如第 1 行有 10 列,第 2 行有 5 列...)
解决方案
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 的详细问题,您可以在此处发布。
PS。我在 Aspose 担任支持开发人员/传播者。
推荐阅读
- node.js - 使用 NodeJS 在 mssql 中创建嵌套事务
- node.js - 运行 gulp 时出现“AssertionError [ERR_ASSERTION]:必须指定任务函数”
- android - 检测 Android 设备是否可折叠?
- percentage - 计算特定值的百分比?
- javascript - 在我的 Firebase 应用程序中写入然后读取数据的推荐方法是什么?
- react-native - 有没有办法把 `options` 变成和 `navigationOptions` 一样的功能呢?
- udp - lwIP telnet 连接的密码保护
- reactjs - 类型错误:list.push 不是函数
- php - 在链配置的命名空间 App\Document 中找不到类“App\Repository\UsersRepository”
- python - 当我使用 Flask 渲染模板时,为什么我的 html 代码没有输出变量的值?