我想从 Excel 中删除整行,
我努力了removeRow
:
XSSFRow rerow = sheet1.getRow(1);
sheet1.removeRow(rerow);
and shiftRows
:
int rowIndex = 1;
int lastIntext = sheet1.getLastRowNum();
sheet1.shiftRows(rowIndex+1, lastIntext, -1);
但它只删除行中的值而不是整行。
即使我也遇到了同样的问题,但经过几次研究后发现
有一个错误/或者他们可能改变了行为<version>4.0.0</version> and <version>4.0.1</version>
阿帕奇波伊
为了
sheet1.shiftRows(rowIndex+1, lastIntext, -1);
请用
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
并使用您的代码更好的方式来删除您的行,如下所示
public static void removeRow(Sheet sheet, int rowIndex) {
int lastRowNum = sheet.getLastRowNum();
if (rowIndex >= 0 && rowIndex < lastRowNum) {
sheet.shiftRows(rowIndex + 1, lastRowNum, -1);
}
if (rowIndex == lastRowNum) {
Row removingRow = sheet.getRow(rowIndex);
if (removingRow != null) {
sheet.removeRow(removingRow);
}
}
}
这对我有用。
也许他们可能会在下一个 api 版本中更新它
如果对您有帮助的话谢谢
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)