import org.apache.poi.xssf.SXSSFITestDataProvider;\r
import org.apache.poi.xssf.XSSFTestDataSamples;\r
import org.apache.poi.xssf.streaming.SXSSFWorkbook;\r
+import org.junit.Test;\r
\r
/**\r
* @author centic\r
}\r
}\r
}\r
+\r
+ \r
+ @Test\r
+ public void test57165() throws IOException {\r
+ XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx");\r
+ try {\r
+ removeAllSheetsBut(3, wb);\r
+ wb.cloneSheet(0); // Throws exception here\r
+ wb.setSheetName(1, "New Sheet");\r
+ //saveWorkbook(wb, fileName);\r
+ \r
+ XSSFWorkbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(wb);\r
+ try {\r
+ \r
+ } finally {\r
+ wbBack.close();\r
+ }\r
+ } finally {\r
+ wb.close();\r
+ }\r
+ }\r
+\r
+ private static void removeAllSheetsBut(int sheetIndex, Workbook wb)\r
+ {\r
+ int sheetNb = wb.getNumberOfSheets();\r
+ // Move this sheet at the first position\r
+ wb.setSheetOrder(wb.getSheetName(sheetIndex), 0);\r
+ for (int sn = sheetNb - 1; sn > 0; sn--)\r
+ {\r
+ wb.removeSheetAt(sn);\r
+ }\r
+ }\r
}\r