I am getting an exception when inserting more than 1.2 million records. Successfully inserted 1 047 000 records in 1 sheet and when creating the new sheet to insert the rest of the records, I am getting
java.lang.IllegalArgumentException: The workbook already contains a sheet of this name
I am using this condition for creating the new sheet
if(rowCount>1047000){
wsSheet = createSheet(sheetName, xssfWorkbook);
createHeader(wsSheet, columsnList, xssfWorkbook, null,listResult.isNameFieldRequired());
rowCount = 1;
}
Tried of changing the sheetName
in
wsSheet = createSheet(sheetName, xssfWorkbook) as sheetName+"1"
but still the same exception.
There is some oddity in the way the org.apache.poi.ss.usermodel.Sheet
checks if a string is already used as a sheet's name: the candidate name is truncated using name.substring(0, 31) and compared to existing names truncated the same way, so you have to make strings differ in at least a character in this range.
XSSFSheet newSheetName = workbook.createSheet("sheetName"+1);
That should simply work. Then depending on your code, you may need to increase the newSheetName variable scope.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With