我试图删除第三行如何使用apache poi删除一行
这是我根据rgettman,Leo,zibi的评论所做的编辑。谢谢。
public class MainTest {
public static void main(String[] args) throws IOException {
FileInputStream file = new FileInputStream(new File("test.xlsx"));
XSSFWorkbook wb = new XSSFWorkbook(file);
XSSFSheet sheet = wb.getSheetAt(0);
sheet.removeRow(sheet.getRow(3));
// sheet.shiftRows(3, 3, -1);
File outWB = new File("testResult.xlsx");
OutputStream out = new FileOutputStream(outWB);
wb.write(out);
out.flush();
out.close();
System.exit(0);
}
}
但这删除值在一排,但如果您正在使用XLS文件(而不是XLSX),那么你应该使用HSSFWorkbook工作不会删除该行
我希望excel不期待xlsx文件 – Leo
您正在将行3向下移动1.使用负数向上移位。 – rgettman