You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by basavarajkanavalli <ba...@gmail.com> on 2012/02/13 14:21:30 UTC

XSSF writer gives me the error while writing into a new file

Hi,

When I am trying to write into a new .xlsx file using POI XSSFwrite, it
gives me the following error:

org.apache.poi.openxml4j.exceptions.InvalidOperationException: Can't open
the specified file:
'/home/bkanavalli/temp/working/reports/ZYMECUSTOMER/temp/Country-ZYMECUSTOMER-1.xlsx'
	at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:102)
	at org.apache.poi.openxml4j.opc.Package.open(Package.java:72)
	at
com.zyme.ChannelInv.Utility.PoiXSSFExcel2007Export.createWorkbook(PoiXSSFExcel2007Export.java:109)


Here is my code listing:

/**
	 * @param file
	 * @param worksheetName
	 * @return
	 */
	public boolean createWorkbook(File file, String worksheetName) {
		try {
			
		
			
			
			File file1 = new File(file.getAbsolutePath());
			
		
			
			Package pkg = Package.open(file1.getAbsolutePath(),
PackageAccess.READ_WRITE);
			
			this.workbook = new XSSFWorkbook();
			
			Sheet sheet = workbook.createSheet("data1");
			
			String fileName = file1.getAbsolutePath();

			FileOutputStream outputStream = new FileOutputStream(fileName);
			workbook.write(outputStream);
			outputStream.close();
			
		} catch (Exception e) {
			logger.info("Exception in createWorkbook " );
			e.printStackTrace();
			logger.error("PoiXSSFExcel2007Export.createWorkbook(): "+ e.getMessage() 
);
		}
		
	}

an somebody help me.
I have already tried the following:
tried to create a file under /tmp/ folder - no luck
tried by providing proper access permission to that file - no luck

the only thing that works is: I created a file using office 2007 and saved
it without nay data in it and then pointed my code towards that. It worked.
But i my application I need to generate the files through the code and
cannot manyally create the files.

Any idea where I am going wrong.
Its a J2EE application.

Regards,
Basu

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/XSSF-writer-gives-me-the-error-while-writing-into-a-new-file-tp5479185p5479185.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org