This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Is it possible to read an ArrayList and write to an XLS file using POIFSFileSystem

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to read from a arraylist and write to a excel. I
reading some records from the DB and trying to write to and excel
file I get -----

java.io.IOException: Unable to read entire header; 88 bytes read;
expected 512 bytes
at org.apache.poi.poifs.storage.HeaderBlockReader.<init>
(HeaderBlockReader.java:78)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>
(POIFSFileSystem.java:83)

My code ----

ResultSet rs2 = stmt2.executeQuery(repSQLStatement);

String filePath = "C:\\test1.xls";
ArrayList al = new ArrayList();
int cols = rs2.getMetaData().getColumnCount();

while (rs2.next()) {
ArrayList record = new ArrayList();
for (int i= 1; i <= cols; i++) {
Object value = rs2.getObject(i);
record.add(value);
}
al.add(record);
}

StringBufferInputStream inputStream = new
StringBufferInputStream(String.valueOf(al));
OutputStream outputStream = new FileOutputStream(filePath);

if (inputStream != null) {
//Here it throws java.io.IOException: Unable to read entire header
POIFSFileSystem poiFS = new POIFSFileSystem(inputStream);
poiFS.writeFilesystem(outputStream);
}
 
Ajay Reddy
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way I am using poi-bin-2.5.1-final-20040804.zip version of POI.

Thanks for your help in advance.
AJ.
 
Ajay Reddy
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I should read my documentation properly. The POIFileSystem class I believe is used to write files from one type to another(xls to xls). If you like to create a xls file by reading data from arraylist then HSSFWorkbook class must be used.

For further information on this class go to http://jakarta.apache.org/poi/hssf/quick-guide.html
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic