0

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.

Karura91
  • 603
  • 6
  • 15
  • 2
    What `apache poi` version used? There are problems using `cloneSheet` when sheet has comments. See https://stackoverflow.com/questions/51559133/poi-3-17-creating-cell-comments-in-a-cloned-sheet-creates-inconsistent-xlsx. Might be other problems too, see https://bz.apache.org/bugzilla/buglist.cgi?bug_status=__open__&content=clonesheet&no_redirect=1&order=changeddate%20DESC%2Cpriority%2Cbug_severity&product=POI&query_format=specific. – Axel Richter Mar 25 '21 at 04:37
  • I am using the version 5.0.0. The sheet we are trying to clone has indeed comments but also control form (checkbox) and from the bugs opened I see that might also be an issue. I guess there won't be an easy solution... – Karura91 Mar 25 '21 at 18:53

0 Answers0