POI HSSF XML to Excel DataFormat Problem

Hiho,
I�ve got the following problem:
I want to create an Excel File from an XML File with POI and DOM4J. This works fine...
Now I want to create some cells with a currency value in it, on which I want to calculate.
Here�s my code:
HSSFSheet sheet = wb.createSheet(s);
HSSFDataFormat format = wb.createDataFormat();
HSSFCellStyle intStyle = wb.createCellStyle();
intStyle.setDataFormat(format.getFormat("(�#.##0,00);(�#.##0,00)"));
     for (cellit = rowelement.elementIterator(); cellit.hasNext();) {
          cellelement = (Element) cellit.next();
          String value = cellelement.getStringValue();
          cell = row.createCell(columnnum);
          s = cellelement.attributeValue("numeric");
          if (s != null) {
               cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
               if (value != null)
                    cell.setCellValue(value);
                    cell.setCellStyle(intStyle);
   ...I always get a value with a prefixed apostrophe in Excel, which says that there�s an int value in a string cell (I think). Has anyone an idea whats wrong with my code? Thanks

http://jakarta.apache.org/site/mail2.html#poi

Similar Messages

  • HOw to implement POI -HSSF in JSP

    Hello Everybody,
    requirement: I have to generate reports of the output from a jsp into excel spreadsheet.
    what i did: Changed the Content type to
    response.setContentType("application/vnd.ms-excel");
    I am getting the output in Excel. But, it is taking long time to display.
    I have searched in the net. I got the information that, i can use POI-hssf to generate Excel report.
    Can any one who have experience on this POI-hssf implementation, could guide me?I couldn't understand details as to what other factors i need to look upon to start using this api in my project. ?!
    Regards.
    AShvini

    NO, Pgeuens !
    What i mean is :
    I have droped idea of using HSSF in my code. I am NOT
    going to use it.
    I can't do it, because, for each user, their
    requirement will be different and input will be
    different for the report. I can't assume all the
    possible inputs and prepare the report in advance !This doesn't seem to be a good reason to drop the idea. Why don't you design a generic interface +class which will allow the report generation as per a set of defined rules?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • 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...

  • 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

  • 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.

  • Poi hssf api to generate MS-Excel file

    I am using apache's poi hssf api to generate an excel file. Is there any way I can FREEZE PANES of excel sheet.
    thanks,
    Pramod

    You're wanting to make certain areas of your spreadsheet un-editable, yes? POI currently does not support this, as mentioned in the FAQ: http://jakarta.apache.org/poi/faq.html#faq-5 .

  • Excel - POI-HSSF - HTML

    Hey guys,
    Im looking for a way to copy an excel file and convert it into a html file. I have found a way to read excel files using POI-HSSF (Fantastic tool by the way). What Im wondering is now that I have the worksheets contents stored in java is there any kind of library that you would recommend that might generate the tables ripped from Excel to HTML automatically?
    Thanks for your help in advance
    Valehru

    YoGee,
    Thanks for the response. Im afraid that the client has insisted that I convert the document to html. I presume that if it was streamed out that it would open an excel worksheet in the browser itself?
    If anyone has any suggestions please let me know. Personally id prefer that they use openoffice and just convert the thing to a pdf but as they say the customer is always right. Im pretty sure that It will take me a fair bit of time trying to parse the data I receive via HSSF into proper valid HTML which looks similar if not identical to the data in the excel file.
    Thanks again for your reply

  • 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...

  • POI-HSSF problem.  saves in /runtime/bin, not /wwwroot

    I am trying to get this to work in Solaris/Apache/MX7. When I
    run the code, it always saves the files in
    <cfusionserver>/runtime/bin/
    with owner "nobody|other"
    i need the files to read and write from
    <cfusionserver>/wwwroot/
    owner "www|www"
    any suggestions?
    files located in <cfserver>/WEB-INF/lib/
    -rw-r--r-- 1 www www 802216 May 16 09:42
    poi-2.5.1-final-20040804.jar
    -rw-r--r-- 1 www www 55209 May 16 09:42
    poi-contrib-2.5.1-final-20040804.jar
    <CFSCRIPT>
    workBook=createObject("java","org.apache.poi.hssf.usermodel.HSSFWorkbook").init();
    newSheet=workBook.createSheet();
    workBook.setSheetName(0, "My First Sheet");
    row=newSheet.createRow(55);
    cell=row.createCell(0);
    cell.setCellValue("hello world!");
    fileOutStream =
    createObject("java","java.io.FileOutputStream").init("test6.xls");
    // ****** output
    workBook.write(fileOutStream);
    fileOutStream.close();
    </CFSCRIPT>
    I have tried using
    .init("/opt/coldfusionmx7/wwwroot/test6.xls"); but i get an error.
    Thanks if you can help
    Dave

    also, you might try creating a file object first, initing
    that with your
    full path, and then passing that object into the init method
    of the output
    stream
    "Marc E" <[email protected]> wrote in message
    news:e4dlop$3t4$[email protected]..
    > what error do you get when trying the init("/opt....")?
    >
    > that's on the right track...just using the filename
    itself is definitely
    > not what you want.
    >
    > what you might do to get the full path you're looking
    for is create a file
    > in wwwroot and do a
    >
    <cfoutput>#getDirectoryFromPath(getCurrentTemplatePath())#</cfoutput>
    >
    > that'll tell you what coldfusion thinks it is, and from
    there you should
    > have what you need to pass into the file init
    >
    >
    > "DaveF67" <[email protected]> wrote in
    message
    > news:e4d0n6$6vh$[email protected]..
    >>I am trying to get this to work in
    Solaris/Apache/MX7. When I run the
    >>code, it
    >> always saves the files in
    >>
    >> <cfusionserver>/runtime/bin/
    >> with owner "nobody|other"
    >>
    >> i need the files to read and write from
    >> <cfusionserver>/wwwroot/
    >> owner "www|www"
    >>
    >> any suggestions?
    >>
    >> files located in <cfserver>/WEB-INF/lib/
    >>
    >> -rw-r--r-- 1 www www 802216 May 16 09:42
    >> poi-2.5.1-final-20040804.jar
    >> -rw-r--r-- 1 www www 55209 May 16 09:42
    >> poi-contrib-2.5.1-final-20040804.jar
    >>
    >>
    >> <CFSCRIPT>
    >>
    >>
    workBook=createObject("java","org.apache.poi.hssf.usermodel.HSSFWorkbook").init
    >> ();
    >> newSheet=workBook.createSheet();
    >> workBook.setSheetName(0, "My First Sheet");
    >> row=newSheet.createRow(55);
    >> cell=row.createCell(0);
    >> cell.setCellValue("hello world!");
    >> fileOutStream =
    >>
    createObject("java","java.io.FileOutputStream").init("test6.xls");
    >> ******
    >> output
    >> workBook.write(fileOutStream);
    >> fileOutStream.close();
    >> </CFSCRIPT>
    >> I have tried using
    .init("/opt/coldfusionmx7/wwwroot/test6.xls"); but i
    >> get an
    >> error.
    >>
    >> Thanks if you can help
    >> Dave
    >>
    >>
    >>
    >
    >

  • XML to Excel file using dom4j

    hi!
    i'm new with dom4j and i don't have any idea on how to do the following task:
    i have an xml document which i have to save as an excel file using dom4j. my problem is i also have to insert records in the middle of the file. is it possible?
    sample layout:
    Worksheet Header (also have to plot a value)
    Column Header (also have to plot a value)
    -- need to insert records here --
    Sub-total row
    Total row
    i would appreciate any help from you guys...
    thanks in advance...

    Hi there!
    First I haven't seen any application that uses dom4j to write excel's file, but I can recommend you to use Apache's POI to write and read from any excel's file, actually I'm working rigth now with it, and works fine with Office 2003.
    http://jakarta.apache.org/poi/hssf/
    For the XML you can use what ever you feel confortable with, dom4j, jdom, etc. I really like jdom thougth

  • Export JSP to Excel : Weird problem  (Urgent)

    Hi,
    Sorry for the length of question.
    I am facing a bit weired problem while exporting my JSP report to Excel.
    I have multiple tables in my JSP page .( Use of Multiple tables is a requirement .).
    I am using Struts and Oracle 9i JDeveloper for developement.
    I have a button called "Excel" and on its click , I am opening the same JSP page in a pop up and passing reqd. parameters to it using querystring
    ( sometimes I am keeping the parameters into session as the length is loo large to fit into queryString. )
    I am using
    response.setContentType("application/vnd.ms-excel");
    to transform my JSP page to Excel.
    Sometimes, this works fine.
    But, mant times this gives error such ( in Windows2000 Adv. Server ) as
    "Memory could not be "read"."..with the tile of error-popup as "Excel.exe".
    (In Windows NT , it never exports to Excel. Every time it gives "Dr. Watson Debugger" message box.)
    In Windows2000 Adv. Server ,
    While debugging, I observed that when I click on Excel button, the pop up opens and executes the page and again goes to the start of the page and executes again and thus tries to open the same Excel document.
    As we know, we cannot open same Excel document twice. Hence it gives a popup alert that
    " The file <filename with its entire path> could not be opened.
    There may be several reasons :
    You might be trying to open a file which does not exist.
    You might be trying to open the file which is already open. ..."
    etc.etc. and something like this.
    Now, this is totally unpredictable. If I click Excel button, It may open the file in excel and on next try it would give error.
    This is quite annoying. I searched on this forum, Google but could not find the solution yet.
    I cannot use POI - HSSF . I cannot use userdefined Excel tags as well. as it will require a lot of reqork and unfortunately I don't have that much time now.
    Please help me and let me know how would I be able to successfully and predictably export my JSP pages to Excel.
    Thanks,
    Swipsy.

    Hi,
    Why don�t you save as attachment? (use -> <% response.setHeader("Content-Disposition", "attachment; filename=\"name.xls\""); %> scriplet )...
    I�m doing the same work, but I have problems to export images to Excel by this method...
    Someone could help me??
    thanks a lot

  • XML to EXCEL with Conversion agent error: XML to EXCEL PROCCES FAILD

    Hello,
    I have scenario from Oracle database to Excel.
    For this scenario I use with conversion agent by itemfield to transfer data from XML to EXCEL.
    The scenario not worked.
    Few points:
    1. I add the conversion agent module to SAP XI receiver communication channel.
    2. When I change the scenario to oracle to xml (without using conversion agent) the scenario works OK.
    3. When I drag the CME file to the studio I found the error message: XML to EXCEL PROCCES FAILD.
    4. I use with conversion agent in other scenario (EDI to IDOC) without any problem.
    5. I'm not found any clue for this problem in XI RWB.
    Elad

    hi Elad,
    to do the conversion,you have to define a module and import it into you CC.
    also see nexts blog
    Yet another "from database or internal table to Excel"
    Reading Excel Data from Java Using HSSF API
    Reading Excel line items using the jExcel API
    Read Excel instead of XML through FileAdapter
    Thanks
    Rodrigo

  • POI-HSSF or Cocoon?

    Hi,
    In our system we have one webb client and one Java application client.
    They both comunicate with the server through 2 difftrent servlets.
    Now I want to implement a method that creates Excel-files on the
    server that both the clients can call.
    I have found information about POI in this forum. When I went to
    http://jakarta.apache.org/poi/hssf/index.html to check it out I read a
    recomendation to use Cocoon instead:
    "If you're modifying spreadsheet data then use the usermodel api. You can also generate spreadsheets this way, but using Cocoon (which will do it this way indirectly) is the best way...we promise."
    So I read about Cocoon too and now I am really confused!!!
    Will they stop developing POI-HSSF?
    Is Cocoon only for webb aplication?
    Can someone please help me?
    :-)Lisa

    I thought Cocoon was a tool for transforming XML into something else. You can probably use Cocoon's ability to transform XML (using POI) into Excel I guess, but Cocoon is not a tool to create Excel spreasheets no.

  • Converting XML to Excel.

    Hi Everybody,
    I have a requirement to have a prebuit XML templete in the database, when a person download it it will populate with some default values in a EXCEL file format.
    How can i acheive this.Please help.
    Thanks

    If I understand you correctly, you have data as XML document and you want to use that data to create a Excel spread sheet. If this is right. I would suggest use any XML binding technoloy such as XMLBeans or JAXB or Castor to parse that document into a Java object and then you can use Apache POI library to generate Excel document. I hope this would help.
    -- Deha Peker

  • Howto import XML into Excel table ?

    Hi,
    I asked this before in the Excel forums but received the suggestion that I ask here instead.  The question precis : How to ungrey the "Append new data to existing XML lists" checkbox so I can select it when importing XML data into an Excel
    spreadsheet.
    I have a local server which provides data in XML form and need to import successive reloads of the XML page into successive lines in an Excel spreadsheet.  I found the Excel help page entitled "How to use XML in Excel 2003" at http://office.microsoft.com/en-gb/excel-help/how-to-use-xml-in-excel-2003-HA001101964.aspx?CTT=1&origin=EC001022986
    which was useful in so far as permitting me to import the data using the XML Source task pane and mapping the elements I need from the XML source to columns in the spreadsheet.
    In order to append successive lines from the XML source page, as I understand it from the link I quoted,  I need to change the XML Map properties to "Append new data to existing XML lists".  However this checkbox is greyed out in the
    XML Map properties dialog box so I can't select it.
    Any ideas how I can achieve my aims here ?
    Thanks in advance,
    Mike

    Hi Mike,
    Thank you for contacting Office IT Pro General Discussions Services. 
    From your description, I understand that you tried to import XML into Excel table. You selected “Use the XML Source
    task pane” when opening the XML file, then you tried to check the option in the
    Map Properties window: "Append new data to existing XML lists". 
    However, this option is grayed out. If there is any misunderstanding, please feel free to let me know.
    I have checked the issue on my side but could not reproduce this issue. I suggest download the sample XML file as suggested on the page and test the
    issue again:
    http://www.microsoft.com/downloads/details.aspx?FamilyId=B4BD3283-AD0B-408D-9CE7-AB9C3537BBBB&displaylang=en
    If the problem does not occur with the sample XML file, this issue might occur as there are some problems with the XML you were using.
    If the problem also occurs in with the sample XML file, this issue might be related to some third-party software conflicts. I suggest checking this
    issue by starting Excel in the safe mode.
    Start the Office program in safe mode
    ==============
    1.      
    Click Start, point to All Programs, and then point to
    Microsoft Office.
    2.       
    Press and hold the CTRL key, and then click
    Microsoft Excel.
    If the problem does not occur in the safe mode, this issue might be related to some third-party add-ins in the Excel program, we can try to disable
    them. Normally, you could do the following to disable the conflict add-ins in your Excel program:
    Disable add-ins
    Click
    Tools > Options > 
    Add-in, click Go button in the Manage:
    Com-in Add.
    Check if there are any add-ins,
    clear the checkbox to disable them.
    Close the Office program and
    restart it.
    Add one check back each time to the list of Add-In,
    restart the Office program, and repeat the above procedure. Once the issue reappears again, we can determine which add-in causes this problem and then disable it.
    Please take your time to try the suggestions and let me know the results at your earliest convenience. If anything is unclear or if there is anything
    I can do for you, please feel free to let me know.
    Best Regards,
    Sally Tang

Maybe you are looking for

  • Is there a way to create a calendar for keynote that automatically updates to current month?

    I use keynote presentations for teaching foreign languages and wanted a calendar that updates automatically to current month everytime I present it rather than making it manually each month.  I'm wondering if it can be done using the keynote date/tim

  • Hours in weekly view

    I know theres an easy answr to this but i cant find it. I read the help topic on this but didnt help.. In my wekly view each day starts at 12am and ends at the time when i put depending on my preferences for total hours showed...i want to view each d

  • Where can I find version 2.0.3 JBoss files required to deploy IM?

    The installation documentation for 1.5.0.8.1 gives URLS for required IM Downloads. The files jboss-native-2.0.3-windows-i686-ssl.zip, axis-bin-1_4.zip, Drools 4.0.7 Binaries, apache-ant-1.7.0-bin.zip, jems-installer-1.2.1.CR4.jar, and JDK 1.6. Not al

  • Viewing multiple application windows simultaneously

    Is it possible to view (float) multiple application windows simultaneously on a MacBook. For example, I am viewing a tutorial on Firefox while working on an image in Photoshop at the same time to try out the suggestions in the tutorial. I have to shi

  • Can siri access your photos and contacts?

    I was wondering if siri can access your photos and personal information And any other info about siri please let me know