POI Help

Hi,
I know that this isn't the ideal place to ask for help for the Apache POI library, but I don't know where exactly to go for help. Can anyone point me to a source or forum that I can look at?
Here's the long version of the story: I am trying to create a .xls file from a .xlt file. I have two templates, and I wrote sample code that basically creates a HSSFWorkbook from the template (in the form of a FileInputStream) and plugs in the String "TEST" into cell D1. It works fine for one template but not the other; I get a NullPointerException when I try to get the first cell of row D. Oddly, I get past that point occasionally but the opening the output file results in a "Unable to read file" error in Excel. I don't quite know where to start looking for help, so I hope someone can kindly point me in the right direction. Any help or advice with regards to debugging this problem would be greatly appreciated. Thanks in advance!

I made a mistake when I described the results. For some reason, I encountered a NullPointerException when I executed sheets.getRow(3). I inspected the properties of the object and discovered that the rows object (a Treemap) in sheets is of size 751, even though sheets.getFirstRowNum is 0 and sheets.getLastRowNum is 758!
When I changed to sheets.getRow(23), it got past the line but rows.getFirstCellNum resulted in 1, so executing cell.setCellValue("TEST") resulted in a NullPointerException. When I assigned row.getCell((short)0) to the cell object instead of row.getCell((short)1), the method terminated with error, but opening "result.xls" generated a "unable to read file" error.
At first, I suspected that the template was not read in properly, but then I located cell B10 (which says "Symbol" in the template) in my method by setting row to sheets.getRow(9) and setting cell to row.getCell((short)1), and right before cell.setCellValue("TEST"), I printed cell.getStringCellValue, which printed "Symbol". I concluded that the template seems to be read in properly.
Here is the modified code:
public void generateFile() {
FileInputStream f = new FileInputStream("template.xlt");
HSSFWorkbook wb = new HSSFWorkbook(f, true);
HSSFSheet sheet = wb.getSheetAt(0);
System.out.println(sheet.getFirstRowNum()); // returns 0
System.out.println(sheet.getLastRowNum()); // returns 757
HSSFRow row = sheet.getRow(9);
System.out.println(row.getFirstCellNum()); // returns 1
System.out.println(row.getLastCellNum()); // returns 11
HSSFCell cell = row.getCell((short)1);
System.out.println("Before edit: " + cell.getStringCellValue()); //prints "Symbol"
cell.setCellValue("TEST");
System.out.println("After edit: " + cell.getStringCellValue()); //prints "TEST"
FileOutputStream out = new FileOutputStream("result.xls");
wb.write(out);
out.close();
} // generateFile
I guess my question at this point is, why are the container objects not correctly reflecting the objects stored? (i.e. How come the last row of sheets is 757 but the size of its row Treemap is only 751?) And why can't I access the first column of the spreadsheet?

Similar Messages

  • POI Help in setting the cell type to Integer.

    Hi,
    Iam facing problem in POI generated excel sheets.
    In some cells Iam writing numeric values.....Its writing properly...
    But Iam unable to use operations like "SUM" on these kind of cells...
    My doubt is still the cell type is being set as String....The part of code I used to set it as numeric is
    <code>
    row.createCell((short)2).setCellTypeHSSFCell.CELL_TYPE_NUMERIC);
    </code>
    Is there any more thing to do so that.....I can enjoy the default features of Excel sheets on my own generated POI excel sheets....
    PLz help me....Any help will be greatly appreciated....
    Thanks in advance,,
    PLz ask me.....If the problem is not clear........

    Can u plz send the Jakarta url for POI help u
    mentioned above............http://www.google.com/search?hl=en&q=jakarta+poi
    What a time-waster.

  • Wanna export excel tooracle using POI - help

    Hi !
    i need some help i am using Jakarta POI to read excel file i want to read 150 rows starting from 12th Row & have to insert into Oracle Database...
    i have started the coding like follows:
    import java.io.*;
    import org.apache.poi.hssf.usermodel.*;
    import org.apache.poi.poifs.filesystem.*;
    public class test {
           public static void main(String a[]) throws FileNotFoundException, IOException
        POIFSFileSystem fs  =  new POIFSFileSystem(new FileInputStream("c:\\sample.xls"));
        HSSFWorkbook wb = new HSSFWorkbook(fs);
        HSSFSheet sheet = wb.getSheetAt(0);
        HSSFRow row = sheet.getRow(12);
        HSSFCell cell = row.getCell((short)0);
         fileOut.close();
    }i am confused how to read the data & then store it in oracle please HELP & provide me some sample code
    Thanks
    Regrds

    check this link 
    Generate Excel file in Oracle ADF using Apache POI | Techartifact
    and formatting u cn use http://www.techartifact.com/blogs/2013/08/setting-styles-formula-in-excel-file-using-apache-poi.html

  • PDF to .Doc or Docx converter by core java using standard JDK

    Hi
    is it possible to convert a PDF file to .doc and .docx by standard JDK or JRE library without using any thirdparty library?if it is can anyone give me any pointer class reference to start the thing.I need core JAVA function who will simply accept a .pdf file and convert it to .doc.
    kind regards
    Edited by: no one on Oct 3, 2011 12:17 AM
    Edited by: EJP on 3/10/2011 16:20: typos/spelling errors

    so i need to download poi-bin-3.7-20101029.tar.gzYou need to download the latest stable release
    from http://poi.apache.org/download.html
    from wherever you download it from
    and install it $JAVA_HOME/ext??
    Definitely not.* Install it whereever its instructions say, or at least on your CLASSPATH, and tell your IDE about it too.
    Any instruction for its usage??It comes with documentation. This is not an Apache POI help desk. You're asking all these questions in the wrong place.

  • Help needed to loadjava apache poi jars into oracle database.

    Help needed to loadjava apache poi jars into oracle database. Many classes left unresolved. (Poi 3.7, database 11.1.0.7). Please share your experience!

    Hi,
    The first 3 steps are just perfect.
    But with
    loadjava.bat -user=user/pw@connstr -force -resolve geronimo-stax-api_1.0_spec-1.0.jar
    the results are rather unexpected. Here is a part of the log file:
    arguments: '-user' 'ccc/***@bisera7-db.dev.srv' '-fileout' 'c:\temp\load4.log' '-force' '-resolve' '-jarsasdbobjects' '-v' 'geronimo-stax-api_1.0_spec-1.0.jar'
    The following operations failed
    resource META-INF/MANIFEST.MF: creation (createFailed)
    class javax/xml/stream/EventFilter: resolution
    class javax/xml/stream/events/Attribute: resolution
    class javax/xml/stream/events/Characters: resolution
    class javax/xml/stream/events/Comment: resolution
    class javax/xml/stream/events/DTD: resolution
    class javax/xml/stream/events/EndDocument: resolution
    class javax/xml/stream/events/EndElement: resolution
    class javax/xml/stream/events/EntityDeclaration: resolution
    class javax/xml/stream/events/EntityReference: resolution
    class javax/xml/stream/events/Namespace: resolution
    class javax/xml/stream/events/NotationDeclaration: resolution
    class javax/xml/stream/events/ProcessingInstruction: resolution
    class javax/xml/stream/events/StartDocument: resolution
    class javax/xml/stream/events/StartElement: resolution
    class javax/xml/stream/events/XMLEvent: resolution
    class javax/xml/stream/StreamFilter: resolution
    class javax/xml/stream/util/EventReaderDelegate: resolution
    class javax/xml/stream/util/StreamReaderDelegate: resolution
    class javax/xml/stream/util/XMLEventAllocator: resolution
    class javax/xml/stream/util/XMLEventConsumer: resolution
    class javax/xml/stream/XMLEventFactory: resolution
    class javax/xml/stream/XMLEventReader: resolution
    class javax/xml/stream/XMLEventWriter: resolution
    class javax/xml/stream/XMLInputFactory: resolution
    class javax/xml/stream/XMLOutputFactory: resolution
    class javax/xml/stream/XMLStreamReader: resolution
    resource META-INF/LICENSE.txt: creation (createFailed)
    resource META-INF/NOTICE.txt: creation (createFailed)
    It seems to me that the root of the problem is the error:
    ORA-29521: referenced name javax/xml/namespace/QName could not be found
    This class exists in the SYS schema though and is valid. If SYS should be included as a resolver? How to solve this problem?

  • Need some help with POI pls...

    Hi,
    I'm currently using POI to generate MS Excel documents from
    CF.
    I believe it's a great tool because it gave me the
    possibility to export the data on different worksheets, etc.
    Before using POI, I was just using only CF (see PART 1 in
    attached code).
    The advantage was that I could display all 3 tables in 1 page
    and control their display using plain html.
    The disadvantage was that, when the request was to display
    each product details on 1 separate worksheet, I was stuck!
    And this is where using POI becomes interesting!
    However, I've noticed that you can only export 1 query to the
    POI, and my question is:
    Is there a way to pass more than 1 query to the POI, so that
    it displays in the same way as it would using CF (3 different
    blocks or tables)?
    This is because, even though I have to separate each product
    on a separate worksheet, I still need to have the same display i.e.
    1 table for the Overall, then a blank column (separator), 1 table
    for the "Entries", then a blank column as separator again, and then
    1 table for the "Exits". (Forget about the names Overall, Entries
    and Exits, this is just an example. I only need to display 3
    sections of data on the same sheet).
    Now, since I don't know if this is possible or not, I have
    tried to work around the problem differently.
    What I've done is to create 1 query (see PART 2 in attached
    code).
    Now, here I've got a big problem, especially if I'm querying
    data since inception.
    I'm using a MySQL 5.1 database properly partitioned on dates
    (yearly) and then properly indexed.
    I'm currently using SQLYog Enterprise v5.21 as GUI tool for
    my database.
    Here are my observations:
    1. Querying the data in SQLYog itself takes miliseconds
    (around 47ms).
    2. Querying the data via a cfquery takes seconds (around 6-7
    seconds).
    3. Looping through more than 50,000 records to create the
    myQry takes around 4-5 mins. If I test it on my PC, I even have to
    restart jrun!
    Is there any better way to do the following?
    1. Populate the myQry.
    2. Display the data in 3 "blocks" on each sheet using POI.
    Your help will be greatly appreciated :-)
    Thanks and regards,
    Yogesh Mahadnac

    Hi -==cfSearching==-
    Many thanks for your reply.
    At least I've got one now!
    Indeed, I would be very much grateful if you could please
    provide me with an example, if possible, via email to
    [email protected]
    Thanks and regards,
    Yogesh Mahadnac.

  • Jakarda POI project, HELP

    hi, i'm generating Excel report from java.i'm uusing HSSF package for that.While on aligining the cell i got error .help me to recover from it.
    i used for aligning is
    HSSFCellStyle style = wb.createCellStyle();
    style=setAlignment(HSSFCellStyle.ALIGN_RIGHT );
    cell.setCellStyle(style);
    i got the error
    cannot resolve symbol method setAlgnment(short)

    Which object are you calling setAlignment on?
    http://jakarta.apache.org/poi/hssf/quick-guide.html
            HSSFCell cell = row.createCell(column);
            cell.setCellValue("Align It");
            HSSFCellStyle cellStyle = wb.createCellStyle();
            cellStyle.setAlignment(align);
            cell.setCellStyle(cellStyle);

  • Eclipse, Apache POI, compiling jar file. Please help =(

    Hello =) I have written a program in Eclipse using the apache POI library. I have added the POI JAR to my build path and the program runs as it should within Eclipse. Once I export my program to a JAR file, I run it from the command line. Each time I do i get the following error:
    {C:\Documents and Settings\Koneko>java -jar "C:\Documents and Settings\Koneko\Desktop\review.jar"
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/poifs/filesystem/POIFSFileSystem" }
    I have no idea why this is happening and have searched the internet for hours looking for an answer =\
    please help.
    -Matt

    I usually put them in WEB-INF. But I thought it doesn't matter where they are if you define them correctly in the web.xml file.

  • Hello everyone, Need help using POI to access xslx data

    Hi,
    i am trying to make a simple program in OATS which will fetch data and display the output from a xlsx file.
    The file name is DriverAdapter and its java script is as below. I have written a java class called ActionDriver whch performs the actions for me using the POI api. But when i instantiate ActionDriver,
    it is throwing the exception referrring to POI api classes cannot be found. ClassNotFoundException : org.apache.poi.openxml4j.exceptions.InvalidOperationException;
    Can someone help me out to find how can i run this through DriverAdapter. When i tried to run ActionDriver from the same project as a java application by replacing my method with main, it is running fine.
    import oracle.oats.scripting.modules.basic.api.*;
    import oracle.oats.scripting.modules.browser.api.*;
    import oracle.oats.scripting.modules.functionalTest.api.*;
    import oracle.oats.scripting.modules.utilities.api.*;
    import oracle.oats.scripting.modules.utilities.api.sql.*;
    import oracle.oats.scripting.modules.utilities.api.xml.*;
    import oracle.oats.scripting.modules.utilities.api.file.*;
    import oracle.oats.scripting.modules.webdom.api.*;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Iterator;
    import ats.test.ActionDriver;
    public class script extends IteratingVUserScript {
         @ScriptService oracle.oats.scripting.modules.utilities.api.UtilitiesService utilities;
         @ScriptService oracle.oats.scripting.modules.browser.api.BrowserService browser;
         @ScriptService oracle.oats.scripting.modules.functionalTest.api.FunctionalTestService ft;
         @ScriptService oracle.oats.scripting.modules.webdom.api.WebDomService web;
         @ScriptService oracle.oats.scripting.modules.formsFT.api.FormsService forms;
         private static String myData="C:/data.xlsx";
         public void initialize() throws Exception {
              //initializing ActionDriver
              dAction = new ActionDriver();
         * Add code to be executed each iteration for this virtual user.
         public void run() throws Exception{
              dAction.startAction(myData);
         public void finish() throws Exception {
    Below is the code for my ActionDriver
    package ats.test;
    //package sni.test.ats;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Iterator;
    import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
    import org.apache.poi.poifs.filesystem.POIFSFileSystem;
    import org.apache.poi.xssf.usermodel.XSSFCell;
    import org.apache.poi.xssf.usermodel.XSSFRow;
    import org.apache.poi.xssf.usermodel.XSSFSheet;
    import org.apache.poi.xssf.usermodel.XSSFWorkbook;
    public class ActionDriver
         public static void main (String ar[])
         //public void startAction(String myData)
              boolean b = true;
              try
                   XSSFWorkbook wb = new XSSFWorkbook("c:/data.xlsx");
                   //XSSFWorkbook wb = new XSSFWorkbook(myData);
                   XSSFSheet sheet = wb.getSheet(DataConstants.businessFlow);
                   ArrayList businessRule = new ArrayList();
    Iterator rows = sheet.rowIterator();
    String myScripts[];
    while (rows.hasNext())
    XSSFRow row = (XSSFRow) rows.next();
    row = (XSSFRow) rows.next();
    Iterator cells = row.cellIterator();
    while (cells.hasNext())
         XSSFCell cell = (XSSFCell) cells.next();
         if (cell.getCellType()==XSSFCell.CELL_TYPE_NUMERIC )
              businessRule.add(cell.getNumericCellValue());
         else
              businessRule.add(cell.getStringCellValue());
    performAction(businessRule);
              catch(Exception fife)
                   System.out.println("Exception Occured"+fife);
                   b=false;
              /*catch(IOException ie)
                   System.out.println("Error Handling Input File"+ie);
         public static void performAction(ArrayList businessRules)
              Object[] businessRuleArray = businessRules.toArray();
              boolean b=true;
              for (int i=1; i<businessRuleArray.length;i++)
                   if(b)
                        String rule = businessRuleArray.toString();
                        System.out.println(rule);
                   else
                   break;

    [this |http://blogs.oracle.com/aamat/2009/06/load_testing_your_oracle_datab_1.html] Hi
    Is that class located in the same folder as the script.java class?
    If note you will need to add it on the manifest, you can look at this blogs for instructions on how to edit the manifest file.
    Regards
    Alex

  • Help needed in using POI for manipulating Word files

    Hi ,
    I am new to POI. I have to take multiple files as input and write them to an output word file using POI.The input files may be word files, jpg or or any other image files and excel sheets also.
    Is this possible using POI?Is there any example source code available?
    I had another concern .I have downloaded the poi-bin-2.5.1-final-20040804 jar.
    This does not contain any api for hwpf.Where can i find hwpf api?

    HWPF is not included in the standard jar that you will download from the Apache Organisations site. Instead, you need to visit what they tern the scratchpad area - from where the developers grab source to work on - and download HWPF from there. You will have to compile it yourself as well I believe. There is some good news however, I cannot remember the address of the site but I did find a web page with links to pre-built jar's of this area, just have a search with google.
    From my own experiences, I would also reccommend that you look to using JExcel to manipulate Excel worksheets. It does not have the same sort of support for evaluating formulae as HSSF does but it does other things better IMO; little things like exposing the formatting applied to the cell.

  • Required help in hssf poi -creating sheets dynamically

    Dear friends ,
    please help me , here is my reqiurement
    from soma data sourse i will be getting some info now what i need to do is save them to different sheets in excel file (single excel file) for a particular devise . ie , if we printer and scanner i would like to store no of pages printed in on sheet named printer and in another sheet i need to store no of pics that were scanned : no of devices may vary it may be 2 or 3 depending on the situation
    please help me in this regard
    thanking you guyz
    cheers
    harsha

    you would actually have a counter to count the number of rows you inserted into the spreadsheet..once counter hits 1000, just save it as .bak extension?

  • Problema di installazione dei programmi adobe, si bloccano al 42% e poi compare l'errore, come mai? io ho imac 27 del 2011, con l'ultima versione yosemite aggiornata. help me please

    help me please

    Yosemite sometimes has problems, often related to "default" permissions needing to be changed
    -one person's solution https://forums.adobe.com/thread/1689788
    -http://blogs.adobe.com/creativecloud/creative-cloud-and-yosemite/
    -https://helpx.adobe.com/x-productkb/global/mac-os-yosemite-compatability.html
    Please read https://forums.adobe.com/thread/1499014
    -try some steps such as changing browsers and turning off your firewall
    -also flush your browser cache so you are starting with a fresh browser
    http://myleniumerrors.com/installation-and-licensing-problems/creative-cloud-error-codes-w ip/
    http://helpx.adobe.com/creative-cloud/kb/failed-install-creative-cloud-desktop.html
    or
    A chat session where an agent may remotely look inside your computer may help
    Creative Cloud chat support (all Creative Cloud customer service issues)
    http://helpx.adobe.com/x-productkb/global/service-ccm.html

  • Need help in POI plugin in java

    Hi,
    I am doing a monthly status report using POI plug-in.
    Now i am having problem: for example to SUM the cells to one cell:
    Example : A1=SUM(A2+A3) ( its working fine)
    but if i do SUM for more cells using " : " this caracter its not working :(
    =SUM(A1:A10)
    How to slove the problem ?
    Hope to hear from you soon :)
    Cheers,
    Sundar Rajagopal

    Several solutions:
    1) Use A1+A2+A3+...+A10 instead.
    2) Rise a bug/feature report at their website/issuetracker and hope that they get it fixed in next release.
    3) Try another Excel API's, such as JExcelAPI at Sourceforge.net.

  • Java and Excel sheet (hssf poi) creating back up  please help!!

    Dear friends , i have a problem i saved some data into some excel file using HSSF POI . after raeching some lines say a maximum of 1000 lines ) i have to save the EXCEL sheet as backupfile with the extention .bak and then delete the original Excel file . did any body have some idea about this . i know you guyz are gurus so please give some advise
    thanks in advance
    cheers
    harsha

    you would actually have a counter to count the number of rows you inserted into the spreadsheet..once counter hits 1000, just save it as .bak extension?

  • Help, I can not use complex formulas in Jakarta POI.

    I have written, the formula from two parts to Excel cells, example:
    SUMIF(A1:A10;RED;B1:B10)/COUNTIF(A1:A10;RED)
    such at opening the document in Excel this field value is #VALUE.
    How it is possible to solve this problem?

    search index has to be pre-built. The steps to do the same are included (or so I remember) alongwith the documentation.
    HI Ajay Das :
       I have searched the "help on help". but i can not found  the steps, what can i do now ?
    best regards

Maybe you are looking for