我試圖刪除第三行如何使用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