String xlsxPath = "C:\\path\\test.xlsx";
Workbook wb = WorkbookFactory.create(new FileInputStream(xlsxPath));
// get first row
Row row = wb.getSheetAt(0).getRow(0);
// remove second cell from first row
row.removeCell(row.getCell(1));
// save changes
FileOutputStream fileOut = new FileOutputStream(xlsxPath);
wb.write(fileOut);
fileOut.close();
2 回答
我没看到你的代码有什么问题 . 删除单元格后,您是否记得保存更改?以下代码对我来说很好 .
您可以尝试将单元格值设置为null或空字符串 .