Closed tgmweb closed 2 months ago
Where did you find that method signature for createSheet()
with `positionSheet' as a third argument? I can't see it in the POI docs:
https://poi.apache.org/apidocs/dev/org/apache/poi/xssf/usermodel/XSSFWorkbook.html#createSheet-- https://poi.apache.org/apidocs/dev/org/apache/poi/ss/usermodel/Workbook.html#createSheet--
It seems to only support the option of specifying the sheet name.
But it's certainly possible to re-order sheets so we could have a new moveSheet()
method.
In fact you can do it now using this unsupported helper method:
spreadsheet.getSheetHelper().moveSheet( workbook, sheetName, moveToIndex );
...bearing in mind that moveToIndex
will be 0-based, i.e. 0 is the position of the first sheet.
My bad, I misread a SO article which is what you suggested; a helper method to reorder the sheets once created. This is perfect and enough for me!
https://stackoverflow.com/questions/16626401/ordering-of-sheets-in-excel-in-apache-poi
As I say, helper methods aren't supported, so it might change or be removed in the future. It's OK for now as a workaround to do what you're looking for, but I will create a new supported moveSheet()
method as part of the public API in the next release.
The apache POI createSheet method includes an option position of the sheet in the workbook:
createSheet(XSSFWorkbook book, String nameSheet, Integer positionSheet)
The third argument in this moduled is "overwrite" instead. Is there a way of creating a sheet in a specific position, or moving the sheets around once they're added?