Looking at your code, I suspect that you have simply misunderstood the way
POI works. When you call the write method on a workbook object - the
HSSFWorkbook instance - it needs to process the various data structures that
have been created - the sheets, cells, etc - in order to generate the file.
What you have done by creating a method that returns bytes is simply
prevented this process from occurring. The write method will see a stream of
bytes but cannot know what they represent.
If you are starting out with POI, then I would change your code and create a
method that performs the whole process from start to end, Pass the List into
it to create the cells and the name of the file but include in that method
the creation of the HSSFWorkbook, the addition of all of the sheets, rows,
and cells and the write method. It would look a little like this;
private void createWorkbook(List data, String filename) {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("Sheet One");
HSSFRow row = null;
HSSFCell cell = null;
// Iterate through your data creating rows and cells and needed;
FileOutputStream fos = new FileOutputStream(new File(filename));
workbook.write(fos);
}
and that ought to do it - and of course I have not included any exception
handlng here as it is just a simple example.
Once you understand how POI works, then you can create methods to, for
example, set up all of you cell styles before you begin building the
workbook, create sheets from the data you supply, etc. If you need further
help there are lots of examples along with a quicku guide, how to and faq at
the Apache POI website.
Yours
Mark B
--
View this message in context:
http://apache-poi.1045710.n5.nabble.com/new-bee-error-when-opening-excel-tp3349074p3349226.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]