When I run the below code I got this error.
org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException: The supplied data appears to be a raw XML file. Formats such as Office 2003 XML are not supported
OPCPackage pkg = OPCPackage.open(filename);
XSSFReader r = new XSSFReader( pkg );
SharedStringsTable sst = r.getSharedStringsTable();
XMLReader parser = fetchSheetParser(sst);
InputStream sheet2 = r.getSheet("rId7");
wb = new XSSFWorkbook(sheet2);
It works fine if I write
wb = new XSSFWorkbook(pkg);
insted of
wb = new XSSFWorkbook(sheet2);
But it creates the all sheets from my old excel. I dont want it. Because my old excell is very huge.
Is there a way to create only one sheet excel file from the old excel's sheet which Relative id is "rId7" ?
new XSSFWorkbook()
requires an .xlsx
file as input. That is a zip file with the .XLSX structure. It will not work if all you give it is raw XML. You can try opening the file you want, and then delete the sheets you don't want to keep.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.