I have an excel template file I am retrieving from minIO, I perform some writing operation on this excel and I finally return the modified file to the user calling my code. This flow was working fine until I tried to clone one of the sheet of my excel. When I do that and I try to open it with Excel the file looks to be corrupted and Excel won't open it. I am a bit lost, I am not sure what could cause this behaviour. I tried to clone an empty sheet I created for testing and it was working, so it might be related to the content of the sheet I am trying to clone but I have no idea as everything runs fine in the code.
So, theses are the part I consider relevants (getting the file from minIO, the moment I clone the sheet and finally when I write to a ByteArray)
try (InputStream inputStream = minioClient.getObject(
GetObjectArgs.builder()
.bucket("someBucket")
.object("someObject.xlsx")
.build()
)) {
Workbook workbook = new XSSFWorkbook(inputStream);
...
Sheet newSheet = workbook.cloneSheet(workbook.getSheetIndex(sheetTemplate));
workbook.setSheetName(workbook.getSheetIndex(newSheet.getSheetName()), "newName");
workbook.setSheetOrder("newName", workbook.getSheetIndex(sheetTemplate));
newSheet.getRow(10).getCell(2).setCellValue("someValue");
...
ByteArrayOutputStream bos = new ByteArrayOutputStream();
workbook.write(bos);
workbook.close();
return Optional.of(bos.toByteArray());
}
I know the question is pretty vague but maybe there is something in the way I handle this flow that it's incorrect although everything worked fine before I tried to clone some of the sheet of our template. Any pointer would be highly appreciated. Thank you in advance.