【发布时间】:2014-06-10 03:58:11
【问题描述】:
我需要一种在预先存在的行之间插入新单元格和/或行而不删除任何行的方法。
我尝试使用:
public static void addRow(File f, int amount, int currentRow)
throws Exception {
FileInputStream file = new FileInputStream(f);
XSSFWorkbook workbook = new XSSFWorkbook(file);
XSSFSheet sheet = workbook.getSheetAt(0);
sheet.shiftRows(currentRow, currentRow + amount, amount, true, true);
file.close();
FileOutputStream out = new FileOutputStream(f);
workbook.write(out);
out.close();
}
但不幸的是,它删除了一些行以适应这种转变。删除的行似乎是随机的,它们实际上并不直接位于移位行的下方或上方。如果我移动超过一排,它们似乎发生在移动的行之间。
提前感谢您的帮助。
【问题讨论】:
标签: java excel apache apache-poi