I am working on a project that needs to read an Excel workbook, calls the necessary web services, and then takes a response from the web services and enters this information into the same Excel workbook that was read.
Here is the error that I see when I try to write to an Excel workbook:
Exception in thread "main" org.apache.poi.POIXMLException: java.io.IOException: Can't obtain the input stream from /docProps/app.xml at org.apache.poi.POIXMLDocument.getProperties(POIXMLDocument.java:141) at org.apache.poi.POIXMLDocument.write(POIXMLDocument.java:177) at ext.ExcelProcessor.main(ExcelProcessor.java:197) Caused by: java.io.IOException: Can't obtain the input stream from /docProps/app.xml at org.apache.poi.openxml4j.opc.PackagePart.getInputStream(PackagePart.java:500) at org.apache.poi.POIXMLProperties.<init>(POIXMLProperties.java:75) at org.apache.poi.POIXMLDocument.getProperties(POIXMLDocument.java:139) ... 2 more
Here is my code for opening a file / reading:
pkg = OPCPackage.open(xslFile); theWorkbook = new XSSFWorkbook(pkg);
After that, I read each row and retrieve each cell value.
Once this is done, I will create cells under the headings for the message โSuccess and Result,โ and then do the following:
String sessionData = sessionKey[1]; String[] cellValCurrRow = rowCellVals.get(r-1); String attachmentData[] = WQSServices.uploadAttachment(sessionData, cellValCurrRow); XSSFCell cell = xslRows[r].getCell(7); if(cell == null) { cell = xslRows[r].createCell(7); } System.out.println("The Cell: "+cell.getStringCellValue()); XSSFCell cell2 = xslRows[r].getCell(8); if(cell2 == null) { cell2 = xslRows[r].createCell(8); } System.out.println("The Cell: "+cell2.getStringCellValue()); cell.setCellType(Cell.CELL_TYPE_STRING); cell2.setCellType(Cell.CELL_TYPE_STRING); cell.setCellValue(attachmentData[0]); cell2.setCellValue(attachmentData[1]); System.out.println("New Cell Data: 1-"+cell.getStringCellValue()+" 2-"+cell2.getStringCellValue()); FileOutputStream fos = new FileOutputStream(xslFile); theWorkbook.write(fos); fos.close();
Has anyone encountered a similar problem?
java excel-2010 apache-poi
Matthew lancaster
source share