Results 1 to 3 of 3
  1. #1
    siteregsam is offline Member
    Join Date
    May 2010
    Posts
    4
    Rep Power
    0

    Default copying a excel sheet from a workbook to another through java

    Hi,

    I am trying to copy a excel sheet from one workbook to another using POI api in java. To be more clear, lets say we have two workbooks bookA and bookB both having two sheets. I want to copy sheet2 of bookA to sheet2 of bookB.

    Help me with some code snippets if you came across any...
    Thanks in advance...
    Last edited by siteregsam; 03-31-2011 at 04:42 PM.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    IOW "do my work for me". No. The examples on their website show both reading a sheet and creating/writing a sheet. So combine those two things.

  3. #3
    siteregsam is offline Member
    Join Date
    May 2010
    Posts
    4
    Rep Power
    0

    Default IOException Exception Invalid header signature

    I tried and got it. The program works fine as a stand-alone application. I tried to integrate the code to an existing code. I got an issue. The following is the code

    // create FOS for PnR sheet
    FileOutputStream csvFileOut = new FileOutputStream(pnrCsvFileName);
    System.out.println("===> csvFileOut created");

    InputStream srcFis = new FileInputStream(fileName);

    HSSFWorkbook srcWb = new HSSFWorkbook(srcFis);

    //get the PnR sheet for excel
    HSSFSheet excelPnrSheet = (HSSFSheet) srcWb.getSheet("PnR Input Data");

    //create a new csv workbook
    HSSFWorkbook csvWorkbook = new HSSFWorkbook();
    //create a sheet in the csv file
    HSSFSheet csvPnrSheet = (HSSFSheet) csvWorkbook.createSheet("PnR Input Data");
    boolean copyStyle = false;

    //start copying
    excelToCsvUtilObj.copySheets(csvPnrSheet, excelPnrSheet, copyStyle);
    System.out.println("===> COPIED!!!");
    //write the excel and csv files
    csvWorkbook.write(csvFileOut);

    csvFileOut.close();
    srcFis.close();

    When i run the application, the execution of the line
    HSSFWorkbook srcWb = new HSSFWorkbook(srcFis) reports
    IOException Exception Invalid header signature; read 63361219987247567, expected -2226271756974174256

    copySheets() methods works fine in the stand-alone application.

    It seems some problem occurs while creating InputStream srcFis at "InputStream srcFis = new FileInputStream(fileName)" and
    fileName is available and its pointing to the right file.

    Kindly help me if anyone experience/knows about the problem..
    Thanks in advance...

Similar Threads

  1. Replies: 0
    Last Post: 09-10-2010, 12:48 PM
  2. Open an Excel workbook
    By ch7787 in forum New To Java
    Replies: 5
    Last Post: 07-20-2010, 05:20 PM
  3. How To Add More Rows To Excel Sheet In Java
    By JMartins in forum New To Java
    Replies: 0
    Last Post: 12-30-2009, 11:30 PM
  4. Replies: 0
    Last Post: 03-11-2008, 02:20 PM
  5. Replies: 0
    Last Post: 08-02-2007, 12:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •