When returning an InputStream in a DataSource implementation, make sure that you are not using HSSWorkbook.getBytes (), as this will only return a specific part of the table (which cannot be used by itself), and not the entire file. Use the write () method instead of ByteArrayOuputStream. For instance:
public InputStream getInputStream() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
workbook.write(baos);
return new ByteArrayInputStream(baos.toByteArray());
}
Just be careful about the size of the spreadsheet as this happens in memory. Consider storing a spreadsheet instead and adding it using a regular FileDataSource file.
HSSFWorkbook.getBytes ()
source
share