Question

I have an xls spreadsheet that I'm querying using metaModel, and I want to keep the xls file in the jar, because it won't be updated. The method used for creating the data context doesn't allow inputstreams, I tried using this code:

DataContext dataContext = DataContextFactory.createExcelDataContext(getClass().getResourceAsStream("database.xls"));

Unfortunately this doesn't work, as the method createExcelDataContext doesn't take inputstreams as a parameter. Is there any way to keep the file in the jar?

It seems the easiest way to do this is just export to csv, as this is easily done.

Was it helpful?

Solution

Given that other kinds of contexts can be created from an InputStream, I would guess that it's a limitation of Excel, and that you won't be able to open the Excel file if it isn't on the file system.

Consider extracting the file from the jar and copy its content to a temporary file, possibly deleted when the application ends. See File.createTempFile() and File.deleteOnExit().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top