Excel File Management Apache POI HSSF vs. jxl jar

I've been reviewing Java technologies for managing Excel files, and I'm a little confused about the differences between Apache's POI HSSF implementation and JExcelApi, and utimately what technology it makes sense to use.
They are both open source, although POI is backed by Apache, where JExcelApi seems to be open source developed by Andy Khan. It seem Apache has a little more weight, therefore may be a better option.
Can someone who has exposure to these technologies please provide me with some insight.
Thanks.

Hi
Thanks for your reply,
Now I hav used an alternate approach of using Apache POI.
But.......
I have created simple table in jsp and set content type to
<%@ page contentType="application/vnd.ms-excel" %>
when i navigate to this jsp it is getting displayed in excel format.
I wish if user clicks on to navigate for this jsp, he must get an option to either open, save or cancel the jsp.
Then on selecting save a dialogue gets appeared where he can select path and file name.
Please comment.
Thanks.

Similar Messages

  • Excel Parsing -org.apache.poi.hssf.record.RecordFormatException

    Hi ,
    I am running into org.apache.poi.hssf.record.RecordFormatException,
    while creating excel work book.
    Few of the worksheets in the workbook are password protected.
    If i remove the password proted worksheets then i am able to load the
    workbook and can parse it.
    I am using apache poi 2.5.1.
    Is it possible to load workbook having few password proted sheets using apache POI?
    I appreaciate any help in this.
    Thanks in advance
    Mark
    code.
    POIFSFileSystem fs =new POIFSFileSystem(input);
    HSSFWorkbook wb = new HSSFWorkbook(fs);
    Exception log:
    java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:80)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java(Compiled Code))
    at java.lang.reflect.Constructor.newInstance(Constructor.java(Compiled Code))
    at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java(Compiled Code))
    at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java(Compiled Code))
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:163)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:130)
    at com.cargill.aim.examples.ExcelParseTest.main(ExcelParseTest.java:43)
    Caused by: java.lang.ArrayIndexOutOfBoundsException
    at java.lang.System.arraycopy(Native Method)
    at org.apache.poi.hssf.record.UnknownRecord.<init>(UnknownRecord.java:62)
    at org.apache.poi.hssf.record.SubRecord.createSubRecord(SubRecord.java:57)
    at org.apache.poi.hssf.record.ObjRecord.fillFields(ObjRecord.java:99)
    at org.apache.poi.hssf.record.Record.fillFields(Record.java(Compiled Code))
    at org.apache.poi.hssf.record.Record.<init>(Record.java(Compiled Code))
    at org.apache.poi.hssf.record.ObjRecord.<init>(ObjRecord.java:61)
    ... 9 more
    Exception in thread "main" org.apache.poi.hssf.record.RecordFormatException: Unable to construct record instance, the following exception occured: null
    at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java(Compiled Code))
    at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java(Compiled Code))
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:163)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:130)
    at com.cargill.aim.examples.ExcelParseTest.main(ExcelParseTest.java:43)

    Hi,
    I am dealing with the similer problem but the same error. I am using the latest version of POI 3.0.1 and trying to read the cells which have auto formating enabled for date. I am getting the same error. Please let me know if you come across any solution to read the formatted cells using POI.
    Thanks in advance!
    - Alok

  • ERROR:java.lang.NoClassDefFoundError: org/apache/poi/hssf/util/HSSFColor$WH

    hi All
    please help me in solving that problem, this error occurs when running my project, its for generating report using jasper report tool, exact at the line
    "JRXlsExporter exporter = new JRXlsExporter();"
    her is the code
    try
            JasperCompileManager.compileReport("E:/jasper_template/report2.jrxml");
            tteset = JasperFillManager.fillReport(jasperReport, new HashMap(),new JRResultSetDataSource(rset));
            JasperExportManager.exportReportToPdfFile(tteset,"E:/test.pdf");
            JRXlsExporter exporter = new JRXlsExporter();       
            exporter.setParameter(JRExporterParameter.JASPER_P  RINT,tteset);
            exporter.setParameter(JRExporterParameter.OUTPUT_F  ILE_NAME,"E:/test.xls");
            exporter.exportReport();
          catch (JRException e)
            e.printStackTrace();
          }

    I think you have to include jasperreports-1.2.7.jar in the classpathWhat?
    exporter.setParameter(JRExporterParameter.OUTPUT_F  ILE_NAME,"E:/test.xls");mentions a file test.xls which I assume naturally is an excel file.
    POI can be used to modify/read excel files in java.
    HSSFColor is used in POI
    This leads me to the conclusion that POI is missing from the classpath.
    How on earth did you come to your conclusions?

  • Writing a row to excel file

    I am trying to write a row to an existing excel file using apache POI and JExcelAPI but no luck so far. It somehow just corrupts the file and am unable to open it. Here is the code im using for POI but it gives me NullPointerException at cell.setValue(). If anybody else knows any other API which is easy to use and does it without any problems
    thx
    try {
              String filename = "C:/m/util.xls";
              POIFSFileSystem fs  = new POIFSFileSystem(new FileInputStream(filename));
              HSSFWorkbook wb = new HSSFWorkbook(fs);
              HSSFSheet sheet = wb.getSheetAt((short)1);
              int i = 17;
              HSSFRow row = sheet.getRow(i);
              HSSFCell cell = row.getCell((short) 2);
              cell.setCellValue("test!");
              FileOutputStream fileOut = new FileOutputStream(filename);
              fileOut = new FileOutputStream(filename);
             wb.write(fileOut);
             fileOut.close();
              }catch(Exception e) { e.printStackTrace(); }Edited by: djavia on Oct 31, 2007 6:47 AM

    Don't double post your question:
    http://forum.java.sun.com/thread.jspa?threadID=617605&messageID=3450899#3450899
    /Kaj

  • Uploading excel file

    hi every one .
    i tried to upload an excel file using apache poi.jar in my
    coldfusion page.
    i succesfully uploaded the file buf after doing more than 10
    time it shows me an error like this .
    can any one guide me to solve this error
    11:42:59.059 - Application Exception - in
    /apps1/WebALC_domain/WebALCQA1/WebALCQA1/cfusion-ear/cfusion-war/fb4/fusebox4.loader.cfmx .cfm
    : line 97
    The specified Directory attribute value
    /apps1/WebALC_domain/WebALCQA1/WebALCQA1/cfusion-ear/cfusion-war/fb4/parsed
    could not be created.
    11:42:59.059 - Application Exception - in
    /apps1/WebALC_domain/WebALCQA1/WebALCQA1/cfusion-ear/cfusion-war/fb4/fusebox4.loader.cfmx .cfm
    : line 101
    The specified Directory attribute value
    /apps1/WebALC_domain/WebALCQA1/WebALCQA1/cfusion-ear/cfusion-war/fb4/plugins
    could not be created.
    11:42:59.059 - fusebox.LoadUnneeded Exception - in
    /apps1/WebALC_domain/WebALCQA1/WebALCQA1/cfusion-ear/cfusion-war/fb4/fusebox4.loader.cfmx .cfm
    : line 178
    The full XML load is unneeded because the in-memory copy is
    fully up to date
    11:43:00.000 - Database Exception - in
    /apps1/WebALC_domain/WebALCQA1/WebALCQA1/cfusion-ear/cfusion-war/fb4/model/dabek/engine_f .cfc
    : line 512
    Error Executing Database Query.
    11:43:00.000 - Database Exception - in
    /apps1/WebALC_domain/WebALCQA1/WebALCQA1/cfusion-ear/cfusion-war/fb4/model/dabek/engine_f .cfc
    : line 512
    Error Executing Database Query.
    11:43:01.001 - Database Exception - in
    /apps1/WebALC_domain/WebALCQA1/WebALCQA1/cfusion-ear/cfusion-war/fb4/model/dabek/engine_f .cfc
    : line 512
    Error Executing Database Query.
    11:43:01.001 - Database Exception - in
    /apps1/WebALC_domain/WebALCQA1/WebALCQA1/cfusion-ear/cfusion-war/fb4/model/dabek/engine_f .cfc
    : line 512
    Error Executing Database Query.
    11:43:01.001 - Database Exception - in
    /apps1/WebALC_domain/WebALCQA1/WebALCQA1/cfusion-ear/cfusion-war/fb4/model/dabek/engine_f .cfc
    : line 512
    Error Executing Database Query.
    11:43:02.002 - Database Exception - in
    /apps1/WebALC_domain/WebALCQA1/WebALCQA1/cfusion-ear/cfusion-war/fb4/model/dabek/engine_f .cfc
    : line 512
    Error Executing Database Query.
    11:43:02.002 - Database Exception - in
    /apps1/WebALC_domain/WebALCQA1/WebALCQA1/cfusion-ear/cfusion-war/fb4/model/dabek/engine_f .cfc
    : line 512
    Error Executing Database Query.
    11:43:02.002 - Database Exception - in
    /apps1/WebALC_domain/WebALCQA1/WebALCQA1/cfusion-ear/cfusion-war/fb4/model/dabek/engine_f .cfc
    : line 512
    Error Executing Database Query.
    11:43:02.002 - Database Exception - in
    /apps1/WebALC_domain/WebALCQA1/WebALCQA1/cfusion-ear/cfusion-war/fb4/model/dabek/engine_f .cfc
    : line 512
    Error Executing Database Query.
    11:43:03.003 - Database Exception - in
    /apps1/WebALC_domain/WebALCQA1/WebALCQA1/cfusion-ear/cfusion-war/fb4/model/dabek/engine_f .cfc
    : line 512
    Error Executing Database Query.
    11:43:03.003 - Database Exception - in
    /apps1/WebALC_domain/WebALCQA1/WebALCQA1/cfusion-ear/cfusion-war/fb4/model/dabek/engine_f .cfc
    : line 512
    Error Executing Database Query.
    thanks for valuable information

    Double check your code to make sure you are closing your
    FileInputStreams and cleaning up your java object references. We
    were having a problem with Java not releasing locks on a file it
    was using and it wound up coming down to a missing
    objFileInputStream.close() statement.
    Not sure if that's the problem here, but worth taking a look.
    Also, make sure the account that CF is running under has
    access to modify the directory in your error statement:
    /apps1/WebALC_domain/WebALCQA1/WebALCQA1/cfusion-ear/cfusion-war/fb4/parsed

  • Can I process Excel BIFF5 files, or simply abandon Apache POI?

    To the experienced:
    I am totally new to processing Microsoft Excel files using Java, and embarked on Apache POI. Now it seems I could be completely out of luck because of the Excel files I am to process.
    Now looking back, I realize that what I did with the Excel file I first received (a .xls file) was opening it in Excel 2007 and clicked the Save button. And it was all OK learning POI by processing that file. Now after all the work I have done with that file, I trashed it and got a copy of the original Excel file - as is, without first loading it in Excel 2007 and saving it - and run my java program on it. And I got the following error message talking about BIFF5 and BIFF8:
    C:\Oracle\Middleware\jdk160_18\bin\javaw.exe -client -classpath
    C:\apps11113\JavaExercise\.adf;C:\apps11113\JavaExercise\Basic\classes;C:\java_lib\poi-3.7\poi-3.7-20101029.jar
    -Djavax.net.ssl.trustStore=C:\Oracle\Middleware\wlserver_10.3\server\lib\DemoTrust.jks learnjava.ExcelTest2
    Exception in thread "main" org.apache.poi.hssf.OldExcelFormatException: The supplied spreadsheet seems to be Excel 5.0/7.0 (BIFF5) format.
    POI only supports BIFF8 format (from Excel versions 97/2000/XP/2003)
    My program, when put into production, will run on schedule and unattended, and will have to process the file as is. Am I out of luck and have to look for some other APIs that support BIFF5? Are there such APIs?
    Many thanks for helping!
    Newman

    J. Newman wrote:
    Exception in thread "main" org.apache.poi.hssf.OldExcelFormatException: The supplied spreadsheet seems to be Excel 5.0/7.0 (BIFF5) format.
    POI only supports BIFF8 format (from Excel versions 97/2000/XP/2003)
    My program, when put into production, will run on schedule and unattended, and will have to process the file as is. Am I out of luck and have to look for some other APIs that support BIFF5? Are there such APIs?I'm pretty sure that OpenOffice will. One test you could do is try to open your 5.0 file in OpenOffice, save it as an Excel 97/2000 file (+don't+ delete your original :-) ) and check to make sure that everything is working as expected, and then see if your POI program can process that.
    If it works, you could try downloading the OpenOffice SDK. It's also possible that something like jodConverter could do the job for you (it looks a lot easier to use), but you'd need to check their website.
    Winston

  • Inserting gif/jpeg image into excel through POI-HSSF

    HI,
    I am using jExcel to generate xls file from java. But I have to include image into the excel sheet. but jExcel supports only PNG file format to insert into excel sheet.
    what about POI-HSSF? Does it support inserting images into Excel or not. if supports what type of images it will support?
    I am in urgent need of it. Help me out in this issue
    Thanks

    MinOP wrote:
    > but I can't seem to figure the image part out. I am not
    calling the loadPicture correctly, which is confusing CF.
    You did not mention which version of POI. Did you verify your
    version supports the patriarch.createPicture method? If you are
    using a really old version it might not.
    > loadPicture("asset/images/logo_e2eA.png",
    workSheet))/>
    Does the code actually have access to a loadPicture() method
    or function? I think loadPicture() is a private method in one of
    the example classes: org.apache.poi.hssf.usermodel.examples.*. So
    you may have to write your own version of it. Assuming you have not
    done so already...

  • Using Apache POI 3.2 to create hyperlinks in Excel

    Hello,
    I am new to Java.
    I have written a program that accesses Excel with the Apache POI version 3.2.
    All seems to work until I tried to insert a Hyperlink to a file on the local drive.
    I followed the quick start guide from Apache POI.
    It provides the following code but Java does not appear to find the "createHelper".
    //link to a file in the current directory
    cell = sheet.createRow(1).createCell((short)0);
    cell.setCellValue("File Link");
    link = createHelper.createHyperlink(Hyperlink.LINK_FILE);
    link.setAddress("link1.xls");
    cell.setHyperlink(link);
    cell.setCellStyle(hlink_style);
    Any ideas on how to insert a Hyperlink into Excel would be appreciated.
    Thanks
    Chris

    This seems to be a class in 3.5 beta jar file. Try downloading and using the 3.5 beta

  • Inserting an Image in Excel with POI HSSF

    Has anyone been successful creating an Excel document with an
    embedded image using POI HSSF?
    Create a nicely formatted Excel is no, problem - but I can't
    seem to figure the image part out. I am not calling the loadPicture
    correctly, which is confusing CF.
    <cfset patriarch = newSheet.createDrawingPatriarch()/>
    <cfset patriarch.createPicture(createObject("java",
    "org.apache.poi.hssf.usermodel.HSSFClientAnchor").init(),
    loadPicture("asset/images/logo_e2eA.png",
    workSheet))/>

    MinOP wrote:
    > but I can't seem to figure the image part out. I am not
    calling the loadPicture correctly, which is confusing CF.
    You did not mention which version of POI. Did you verify your
    version supports the patriarch.createPicture method? If you are
    using a really old version it might not.
    > loadPicture("asset/images/logo_e2eA.png",
    workSheet))/>
    Does the code actually have access to a loadPicture() method
    or function? I think loadPicture() is a private method in one of
    the example classes: org.apache.poi.hssf.usermodel.examples.*. So
    you may have to write your own version of it. Assuming you have not
    done so already...

  • Apache Poi Excel Question

    If I use Apacha Poi to create an xls on a machine that doesn't have excel, can I still read the values using Apache Poi HSSF of the create xls?

    yes, POI is independent of Excel being installed.

  • I need a link where I can find "Apache POI - HWPF" jar file

    I want to create a program that reads a word document and I can not find the .jar file of "Apache POI - HWPF". Can anybody send me the link from where I can download it? 10x

    I modified my code as below:
    import java.io.*;
    import org.apache.poi.hwpf.extractor.*;
    public class Word_Reader
    public static void main (String args[])
    try
    InputStream is = new BufferedInputStream(new FileInputStream("test.doc"));
    WordExtractor wd = new WordExtractor(is);
    String text = wd.getText();
    System.out.println(text);
    catch(FileNotFoundException e1)
    System.out.println("File does not exist.");
    catch(IOException e2)
    System.out.println("IO Exception");
    I get printed on console: "IOException". What is wrong in my code?

  • Store data in mysql after reading from excel files

    i am trying to make o program where i will read the data from excel files and i will store them in a database. I am using eclipse as editor and mySQL. I am using APACHE POI to read the excel files and JDBC for the connection. The excel files have the structure as shown below:
    ID NAME SALARY STREET
    321 TIM 1254 14 avenue
    121 PAUL 1265 28h oktovriou
    432 NICK 4521 papaflessa
    I have of course plenty of such files which contains many more rows and columns. The purpose of my program is to read the data, create table named as the name of the excel file and the fields of each table to be the first rows of the excel file. Afterwards the values will be the rest data of the excel file. In the code below i have managed to read them, show the data in the console. Afterwrds i am trying to call a database with JDBC but there i have problem when i create the table.
    try
    String[] allFields;
    String createTableStr = "CREATE TABLE" + createTableStr
    + "(" + org.apache.commons.lang3.StringUtils.join(allFields,
    ",") + ")";
    Could anyone help me?
    Thank you in advance!:)
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.List;
    import org.apache.poi.hssf.usermodel.HSSFCell;
    import org.apache.poi.hssf.usermodel.HSSFRow;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    import org.apache.commons.lang3.StringUtils;
    import org.apache.poi.ss.usermodel.Cell;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.Statement;
    public class exam1 {
    @SuppressWarnings({ "unchecked", "unchecked" })
    static void main (String[] args) throws Exception {
    String filename = "C:\\Users\\Efi\\Documents\\test5.xls";
    List sheetData = new ArrayList();
    FileInputStream fis = null;
    try {
    fis = new FileInputStream(filename);
    HSSFWorkbook workbook = new HSSFWorkbook(fis);
    HSSFSheet sheet = workbook.getSheetAt(0);
    Iterator rows = sheet.rowIterator();
    while (rows.hasNext()) {
    HSSFRow row = (HSSFRow) rows.next();
    Iterator cells = row.cellIterator();
    List data = new ArrayList();
    while (cells.hasNext()) {
    HSSFCell cell = (HSSFCell) cells.next();
    data.add(cell);
    sheetData.add(data);
    } catch (IOException e) {
    e.printStackTrace();
    } finally {
    if (fis != null) {
    fis.close();
    showExcelData(sheetData);
    @SuppressWarnings("unused")
    HashMap<String, String> tableFields = new HashMap();
    for (int i=0; i<sheetData.size();i++){
    List list = (List) sheetData.get(i);
    for (int j=0; j<list.size(); j++){
    Cell cell = (Cell) list.get(j);
    if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
    System.out.print(cell.getNumericCellValue());
    }else if(cell.getCellType()==Cell.CELL_TYPE_STRING) {
    System.out.print(cell.getRichStringCellValue());
    } else if(cell.getCellType()==Cell.CELL_TYPE_BOOLEAN) {
    System.out.print(cell.getBooleanCellValue());
    if (j < list.size() - 1) {
    System.out.print(", ");
    private static void showExcelData(List sheetData) {
    @SuppressWarnings("unchecked")
    private HashMap parseExcelData (List sheetData){
    HashMap<String,Integer> tableFields = new HashMap();
    List list = (List) sheetData.get(0);
    for (int j=0; j<list.size(); j++){
    Cell cell=(Cell) list.get(j);
    tableFields.put(cell.getStringCellValue(),cell.getCellType());
    return tableFields;
    @SuppressWarnings({ "unchecked", "unchecked", "unchecked", "unchecked", "unused" })
    private String getCreateTable(String tablename, HashMap<String, Integer> tableFields){
    Iterator iter = tableFields.keySet().iterator();
    String str="";
    String[] allFields = new String[tableFields.size()];
    int i = 0;
    while (iter.hasNext()){
    String fieldName = (String) iter.next();
    Integer fieldType=(Integer)tableFields.get(fieldName);
    switch (fieldType){
    case Cell.CELL_TYPE_NUMERIC:
    str=fieldName + "INTEGER";
    break;
    case Cell.CELL_TYPE_STRING:
    str= fieldName + "VARCHAR(255)";
    break;
    case Cell.CELL_TYPE_BOOLEAN:
    str=fieldName + "INTEGER";
    break;
    allFields[i++]= str;
    return str;
    public Connection getConnection() throws SQLException {
    try {
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/kainourgia","root", "root");
    Statement stmt = con.createStatement();
    try
    System.out.println( "Use the database..." );
    stmt.executeUpdate( "USE kainourgia;" );
    catch( SQLException e )
    System.out.println( "SQLException: " + e.getMessage() );
    System.out.println( "SQLState: " + e.getSQLState() );
    System.out.println( "VendorError: " + e.getErrorCode() );
    try
    String[] allFields;
    String createTableStr = "CREATE TABLE" + createTableStr
    + "(" + org.apache.commons.lang3.StringUtils.join(allFields,
    *",") + ")";*
    System.out.println( "Create a new table in the database" );
    stmt.executeUpdate( createTableStr );
    catch( SQLException e )
    System.out.println( "SQLException: " + e.getMessage() );
    System.out.println( "SQLState: " + e.getSQLState() );
    System.out.println( "VendorError: " + e.getErrorCode() );
    catch( Exception e )
    System.out.println( ((SQLException) e).getSQLState() );
    System.out.println( e.getMessage() );
    e.printStackTrace();
    return null;
    }

    Please don't multipost! Also crossposted: http://www.java-forums.org/jdbc/71612-store-data-mysql-after-reading-excel-files.html
    Mod: I'm locking this thread.

  • Error reading zip file containing an excel file

    Hi all,
    Using servlets I am able to zip an excel file using java.util.zip package. The excel file is created using POI API.
    While I save and extract the zip file on my machine and then open the file in MS Excel. Excel pops a message saying "MS Office Excel has encountered a problem and need to close" and it gives me an option to "Recover my work and restart MS Office Excel". I select the option and then MS Excel does a document recovery and I am able to view my data. I get an excel repair log file saying as follows
    "Microsoft Office Excel File Repair Log
    Errors were detected in file 'C:\Documents and Settings\JohnDoe\Desktop\excel\test.xls'
    The following is a list of repairs:
    Damage to the file was so extensive that repairs were not possible. Excel attempted to recover your formulas and values, but some data may have been lost or corrupted.
    I have attached my servlet code down below I suspect there is a problem with PrintWriter to output or do I need to use OutputStream to write excel data.
    Below is my servlet code:
    import java.io.*;
    import javax.servlet.*;
    import org.apache.log4j.Logger;
    import java.util.*;
    import java.util.zip.*;
    import java.net.*;
    import org.apache.poi.hssf.usermodel.*;
    import org.apache.poi.hssf.record.*;
    import org.apache.poi.hssf.util.*;
    public class ZipServlet extends HttpServlet {
         * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
         * javax.servlet.http.HttpServletResponse)
         public void doGet(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
              makeZip(request, response, "GET");
         * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
         protected void doPost(HttpServletRequest request, HttpServletResponse response)
                   throws ServletException, IOException {
                   makeZip(request, response, "POST");
         public void makeZip(HttpServletRequest request, HttpServletResponse response, String methodGetPost) {
              Logger logger = Logger.getLogger(ZipServlet.class);
              try
                   int id=1;
                   ServletContext sc = getServletContext();
         HttpSession session = request.getSession();          
                   ConnectionPoolManager cpm = (ConnectionPoolManager)sc.getAttribute("CONNECTION_POOL_MANAGER");
                   ConnectionPool cp = cpm.getConnectionPool(id);
              createTestExcelZip(request,response,methodGetPost,session);
              } catch (Exception e2) {
         public void createTestExcelZip(HttpServletRequest request, HttpServletResponse response,
                   String methodGetPost,HttpSession session
                   )throws ServletException, IOException
              Logger logger = Logger.getLogger(ZipServlet.class);
              try
              {      //Create an Excel Workbook and placing value "Test" in the first cell
                   HSSFWorkbook wb = new HSSFWorkbook();
                   HSSFSheet sheet = wb.createSheet("new sheet");
                   HSSFCell cell=null;
                   HSSFRow row = sheet.createRow((short) 0);
                   short column = 0;
                   cell = row.createCell(column);
                   cell.setCellValue(new HSSFRichTextString("Test"));
                   HSSFCellStyle fontStyle = wb.createCellStyle();
              HSSFFont f = wb.createFont();
              f.setFontHeight((short) 200);
              f.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
              fontStyle.setFont(f);
              cell.setCellStyle(fontStyle);
              response.setContentType("application/zip");
                   response.setHeader("Content-Disposition","attachment; filename=zipExcelRecordFiles.zip;");
                   int BUFFER = 2048;
                   byte buf[]=new byte[300000];
                   ByteArrayOutputStream baos = new ByteArrayOutputStream();
                   ZipOutputStream zos = new ZipOutputStream( baos );
                   ByteArrayInputStream is = null;
                   BufferedInputStream origin = null;
                   byte[] b = null;
                   String fileName = null;
                   b = wb.getBytes();
                   fileName = "testExcelRecords.xls";
                   try
                   is = new ByteArrayInputStream(b);
                   origin = new BufferedInputStream(is, BUFFER);
                   zos.putNextEntry(new ZipEntry(fileName)); // Add ZIP entry to output stream.
              int count;
              while((count = origin.read(buf, 0, BUFFER)) != -1)
              zos.write(buf, 0, count);
              zos.closeEntry(); // Complete the entry
                   is.close();
                   }catch(Exception e)
                        logger.error(e);
                   zos.close();
              PrintWriter pr = response.getWriter();
                   pr.write(baos.toString("ISO-8859-1"));
                   pr.close();
              catch(Exception e)
              logger.error(e);     
         * @see javax.servlet.GenericServlet#destroy()
         public void destroy() {
    Any help would be appreciated.
    Regards
    jdcunha

    Jdcunha,
    I am new to the field but encountered the same problem and recently found a solution. Hope this helps.
    For my project I wanted to create individual Excel 2003 workbooks for each file I created. Excel would give me the same error it gave you when I used the same HSSFWorkbook object. I tried creating a new Workbook object each time, but ran into the same issue.
    I ended up fixing the error by creating a new instance of my write-to-excel class each time I wanted to create a new workbook, instead of just recreating a new HSSFWorkbook object. It works perfectly and the Excel errors don't show. It may also be important to note I used OutputStream, I did not try it with printwriter.

  • How to retrieve data from a read-only Excel file

    Hi Developers,
    I'm trying to retrieve data from a read-only Excel file. I used the same code that I used to retrieve data from a normal Excel file, but it can't work.
    My code is as followed:
    try
    InputStream KpExcel = new FileInputStream("kp.xls");
    HSSFWorkbook Kpwb = new HSSFWorkbook(KpExcel);
    HSSFSheet Kpsheet = Kpwb.getSheetAt(0);
    catch(Exception e)
    e.printStackTrace();
    System.out.println("Exception: "+e.getMessage());
    The error I received is as followed:
    java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
    at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:224)
    at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:160)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:163)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:210)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:191)
    at photoproductionsystem.IncomingWIPPanel.getKp(IncomingWIPPanel.java:118)
    at photoproductionsystem.IncomingWIPPanel.<init>(IncomingWIPPanel.java:76)
    at photoproductionsystem.TabbedDisplay.<init>(TabbedDisplay.java:47)
    at photoproductionsystem.Display.create(Display.java:73)
    at photoproductionsystem.Display.init(Display.java:44)
    at photoproductionsystem.Display.main(Display.java:229)
    Caused by: java.lang.ArrayIndexOutOfBoundsException
    at java.lang.System.arraycopy(Native Method)
    at org.apache.poi.hssf.record.UnknownRecord.<init>(UnknownRecord.java:62)
    at org.apache.poi.hssf.record.SubRecord.createSubRecord(SubRecord.java:57)
    at org.apache.poi.hssf.record.ObjRecord.fillFields(ObjRecord.java:99)
    at org.apache.poi.hssf.record.Record.fillFields(Record.java:90)
    at org.apache.poi.hssf.record.Record.<init>(Record.java:55)
    at org.apache.poi.hssf.record.ObjRecord.<init>(ObjRecord.java:61)
    ... 15 more
    Can someone please help me with my problem? Thanks a lot in advance!

    Madeline wrote:
    how do I ask at Apache mailing list?I wonder why it seems to be a strange idea to some people to look at the software vendor's site for product support. :p
    http://poi.apache.org/mailinglists.html

  • How to export data from a Dynpro table to Excel file?

    Hi
    Here I go again. I read the post <b>Looking for example to export data from a DynPro table to Excel file</b> and put the code lines into a Web Dynpro Project where we need to export a dynpro table to Excel file but exactly at line 23 it doesn't recognize <b>workBook = new HSSFWorkbook();</b>
    1     //Declare this in the end between the Begin others block.
    2     
    3     private FileOutputStream out = null;
    4     private HSSFWorkbook workBook = null;
    5     private HSSFSheet hsSheet = null;
    6     private HSSFRow row = null;
    7     private HSSFCell cell = null;
    8     private HSSFCellStyle cs = null;
    9     private HSSFCellStyle cs1 = null;
    10     private HSSFCellStyle cs2 = null;
    11     private HSSFDataFormat dataFormat = null;
    12     private HSSFFont f = null;
    13     private HSSFFont f1 = null;
    14     
    15     //Code to create the Excel.
    16     
    17     public void onActionExportToExcel(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
    18     {
    19     //@@begin onActionExportToExcel(ServerEvent)
    20     try
    21     {
    22     out = new FileOutputStream("C:/mydirectory/myfiles/testexcel.xls");
    23     workBook = new HSSFWorkbook();
    24     hsSheet = workBook.createSheet("My Sheet");
    25     cs = workBook.createCellStyle();
    26     cs1 = workBook.createCellStyle();
    27     cs2 = workBook.createCellStyle();
    28     dataFormat = workBook.createDataFormat();
    29     f = workBook.createFont();
    30     f1 = workBook.createFont();
    31     f.setFontHeightInPoints((short) 12);
    32     // make it blue
    33     f.setColor( (short)HSSFFont.COLOR_NORMAL );
    34     // make it bold
    35     // arial is the default font
    36     f.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    37     
    38     // set font 2 to 10 point type
    39     f1.setFontHeightInPoints((short) 10);
    40     // make it red
    41     f1.setColor( (short)HSSFFont.COLOR_RED );
    42     // make it bold
    43     f1.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    44     f1.setStrikeout(true);
    45     cs.setFont(f);
    46     cs.setDataFormat(dataFormat.getFormat("#,##0.0"));
    47     
    48     // set a thick border
    49     cs2.setBorderBottom(cs2.BORDER_THICK);
    50     
    51     // fill w fg fill color
    52     cs2.setFillPattern((short) HSSFCellStyle.SOLID_FOREGROUND);
    53     cs2.setFillBackgroundColor((short)HSSFCellStyle.SOLID_FOREGROUND);
    54     // set the cell format to text see HSSFDataFormat for a full list
    55     cs2.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
    56     cs2.setFont(f1);
    57     cs2.setLocked(true);
    58     cs2.setWrapText(true);
    59     row = hsSheet.createRow(0);
    60     hsSheet.createFreezePane(0,1,1,1);
    61     for(int i=1; i<10;i++)
    62     {
    63     cell = row.createCell((short)i);
    64     cell.setCellValue("Excel Column "+i);
    65     cell.setCellStyle(cs2);
    66     }
    67     workBook.write(out);
    68     out.close();
    69     
    70     //Read the file that was created.
    71     
    72     FileInputStream fin = new FileInputStream("C:/mydirectory/myfiles/testexcel.xls");
    73     byte b[] = new byte[fin.available()];
    74     fin.read(b,0,b.length);
    75     fin.close();
    76     
    77     wdContext.currentContextElement().setDataContent(b);
    78     }
    79     catch(Exception e)
    80     {
    81     wdComponentAPI.getComponent().getMessageManager().reportException("Exception while reading file "+e,true);
    82     }
    83     //@@end
    84     }
    I don't know why this happen? Any information I will appreciate it.
    Thanks in advance!!!
    Tokio Franco Chang

    After test the code lines appears this error stacktrace:
    [code]
    java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFWorkbook
         at com.sap.tc.webdynpro.progmodel.api.iwdcustomevent.ExportToExcel.onActionAct1(ExportToExcel.java:232)
         at com.sap.tc.webdynpro.progmodel.api.iwdcustomevent.wdp.InternalExportToExcel.wdInvokeEventHandler(InternalExportToExcel.java:147)
         at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.invokeEventHandler(DelegatingView.java:87)
         at com.sap.tc.webdynpro.progmodel.controller.Action.fire(Action.java:67)
         at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.handleAction(WebDynproMainTask.java:101)
         at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.handleActionEvent(WebDynproMainTask.java:304)
         at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.execute(WebDynproMainTask.java:649)
         at com.sap.tc.webdynpro.clientserver.cal.AbstractClient.executeTasks(AbstractClient.java:59)
         at com.sap.tc.webdynpro.clientserver.cal.ClientManager.doProcessing(ClientManager.java:252)
         at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doWebDynproProcessing(DispatcherServlet.java:154)
         at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doContent(DispatcherServlet.java:116)
         at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doPost(DispatcherServlet.java:55)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:392)
         at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:266)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:345)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:323)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:865)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:240)
         at com.sap.engine.services.httpserver.server.Client.handle(Client.java:92)
         at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:148)
         at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:37)
         at com.sap.engine.core.cluster.impl6.session.UnorderedChannel$MessageRunner.run(UnorderedChannel.java:71)
         at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:95)
         at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:159)
    Thanks in advance!!!
    Tokio Franco Chang
    [/code]

Maybe you are looking for

  • IPhoto vs. Photoshop Elements 6

    I just bought my first Mac and had no trouble using iPhoto for importing and editing my photos. I then installed Photoshop Elements 6 for Mac (with many hours of support from Adobe, after it repeatedly failed to install properly), and that program wo

  • Adding & formatting text in Acrobat Pro 8

    Summary: I have just upgraded from Acrobat 5 to Acrobat Professional 8. In acrobat 5 it is super easy to add new text and format to desired style, color, size, etc... I can not for the life of me figure out how to ADD text that I can format with font

  • Populating dynamic components in a remotely connected desktop application

    Hii Javaties I develping a desktop appliaction, which will remotely connect to internet. My requiremnets for the project are 1)- Combo boxes, lists are dynamic(they need 2 be populated from databse).Since user will not be always connected to internet

  • Credit Card Encryption & System Copy

    Hi All, We have done a system copy from PRD back to QA (credit card encryption is activated on both servers). The customer would like to be able to read the PRD data including the credit card details but of course the QA system can only de-crypt its

  • Bapi Or Function Module for Updating a table

    Can u Plz let me know , is there any bapi or function module to update few fields of a standard table using an internable.