Firstly, you say that you are reading an Excel 2003 file and then try to use
the POI stream that is designed to process OpenXML files. Those files can
only be written by versions of Excel 2007 and on so it may be that you
should be using the HSSF stream to read the file.
Secondly, you may well have a file that is written using something called
Office XML - at least I think that was the term used. This is an xml file
but not one in a format that POI can process. If it were me, I would try to
open the file using the HSSF stream and if that files, simply try to open it
using a text editor like Wordpad. If you can open it with Wordpad and you
see xml markup then I will guess that you have one of these Office XML
files.
If you are unsure and if the file does not contain any sensitive data, then
you can always attache it to a message and we can take a look for you.
Yours
Mark B
MaYong wrote:
>
> Dear All:
>
> when I used XSSF read Excel 2003 file, had a Exception.read Excel 2007,ok.
> source:
> String excelFile = "newwork_workbook.xls";
>
> // XSSFWorkbook wb=new XSSFWorkbook();
> XSSFWorkbook wb = wb = new XSSFWorkbook(excelFile);
>
> XSSFSheet sheet = wb.getSheetAt(0);
> XSSFRow row = sheet.getRow(2);
> XSSFCell cell = row.getCell(3);
> if (cell == null)
> cell = row.createCell(3);
> cell.setCellType(HSSFCell.CELL_TYPE_STRING);
> cell.setCellValue(new XSSFRichTextString("a test"));
>
> // Write the output to a file
> FileOutputStream fileOut = new FileOutputStream("2007excel.xls");
> wb.write(fileOut);
> fileOut.close();
> Exction:
> Exception in thread "main"
> org.apache.poi.openxml4j.exceptions.InvalidOperationException: Can't open
> the specified file: 'newwork_workbook.xls'
> at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:102)
> at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:199)
> at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:178)
> at org.apache.poi.POIXMLDocument.openPackage(POIXMLDocument.java:62)
> at
> org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:167)
> at PoiTest.readingAndRewritingWorkbooks(PoiTest.java:179)
> at PoiTest.main(PoiTest.java:57)
>
>
--
View this message in context:
http://www.nabble.com/org.apache.poi.openxml4j.exceptions.InvalidOperationException-tp26093031p26099802.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]