java POI API 的 getRow() 和 getLastCellNum()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13505066/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
getRow() and getLastCellNum() of POI API
提问by MKod
I am working with Excel (xlsx) in Java. I never understood the return value type
from getRow(int RowNum)
. What do you mean by "IT RETURNS THE LOGICAL ROW (0-Based)"? See below code.
我正在 Java 中使用 Excel (xlsx)。我从不理解getRow(int RowNum)
. “它返回逻辑行(0-Based)”是什么意思?见下面的代码。
row=sheet.getRow(0);
I am trying to get the data from 3rd row, 1st col. Apparently it worked and I got the result what I need (only after writing bit of further code).
我正在尝试从第 3 行第 1 列获取数据。显然它起作用了,我得到了我需要的结果(只有在编写了一些进一步的代码之后)。
But, my question is how user manage to get data from 3rd row? when the rownum is given as 0 (as you can see). I am expecting that it will (row) stick to 0th row ie. first row in Excel sheet.
但是,我的问题是用户如何设法从第三行获取数据?当 rownum 为 0 时(如您所见)。我期待它(行)坚持第 0 行,即。Excel 工作表中的第一行。
getLastCellNum()
method of XSSFRow class - what do you mean by "Gets the index of the last cell contained in this row PLUS ONE"?.
getLastCellNum()
XSSFRow 类的方法 - “获取此行中包含的最后一个单元格的索引加上一个”是什么意思?。
回答by Didier L
For getRow(int RowNum)
, I think the logical row means it is a logical view on the physical sheet, but if you change the physical rows it will not get updated accordingly.
对于getRow(int RowNum)
,我认为逻辑行意味着它是物理表上的逻辑视图,但是如果您更改物理行,它将不会相应地更新。
For example:
例如:
Row a = sheet.getRow(5);
Row b = sheet.createRow(0); // every physical row gets shifted down
System.out.println(a.getRowNum()); // still prints 5, logical row has not been updated
Concerning getLastCellNum()
, I think it just means it returns the number of cells in the row (including blank ones). It just happens that the underlying datamodel stores this value and it is returned as-is, and it is also convenient for iterating on cells…
关于getLastCellNum()
,我认为这只是意味着它返回行中的单元格数(包括空白单元格)。碰巧底层数据模型存储了这个值并按原样返回,并且也方便在单元格上进行迭代......