我在第一张纸上使用包含2个表的模板文件。我需要在第一张纸上执行2次操作。
我使用XSSFWorkbook创建了工作簿对象,向下移动了行,然后尝试将工作簿转换为SXSSFWorkbook。但它在执行时会抛出错误
java.lang.IllegalArgumentException: Attempting to write a row[11] in the range [0,30] that is already written to disk.
如果我首先使用SXSSFWorkbook创建工作簿obj,则无法创建
XSSFWorkbook来自它。有人可以建议如何做到。
我试过了:
FileInputStream inputStream = new FileInputStream(new File(filePath));
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
XSSFSheet sheet = workbook.getSheet("Sheet1");
// First shift rows down - WORKS FINE
sheet.shiftRows( tab1HeaderRowNum + 1, sheet.getLastRowNum(), locationRecordsSize - 1);
// Copy style of row on new rows - WORKS FINE
for(int i = 1; i < locationRecordsSize; i++){
sheet.copyRows(tab1HeaderRowNum , tab1HeaderRowNum , (tab1HeaderRowNum + i), cellCopyPolicy);
}
// Create new SXSSFWorkbook
SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(workbook);
SXSSFSheet sxssfSheet = sxssfWorkbook.getSheet("Sheet1");
if(sxssfSheet.getRow(rowNum) == null){ // rowNum is of row which is newly added using shiftRows
row = sxssfSheet.createRow(rowNum); // Error Occurs Here
}else{
row = sxssfSheet.getRow(rowNum);
}
我正在使用Apache POI 3.15