https://bz.apache.org/bugzilla/show_bug.cgi?id=65683
--- Comment #3 from [email protected] --- Created attachment 38096 --> https://bz.apache.org/bugzilla/attachment.cgi?id=38096&action=edit this is extract whole sheet named "attachment1" file from the origin excel this is test case. ``` @Test public void testExtractSheet() throws IOException { Workbook workbook = WorkbookFactory.create(new File("template - 副本.xls")); try { int numberOfSheets = workbook.getNumberOfSheets(); boolean found = false; String sheetNameToExtract = "attachment1"; for (int i = 0; i < numberOfSheets; i++) { Sheet sheetAt = workbook.getSheetAt(i); if (!sheetAt.getSheetName().equalsIgnoreCase(sheetNameToExtract)) { workbook.removeSheetAt(i--); numberOfSheets--; } else { found = true; } } if (!found) { workbook.close(); throw new FileNotFoundException("can not find sheet: " + sheetNameToExtract); } File outputFile = new File(System.currentTimeMillis() + ".xls"); FileUtils.createParentDirectories(outputFile); try (FileOutputStream stream = new FileOutputStream(outputFile)) { workbook.write(stream); } } finally { org.apache.commons.io.IOUtils.closeQuietly(workbook); } } ``` The result is that the original excel file is 847K and the sheet named "attachment1" contains only a simple excel, but when it is extracted to a new file, the new file size is 845K, so I guess poi will not delete the irrelevant files from this sheet. -- You are receiving this mail because: You are the assignee for the bug. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
