Results 1 to 16 of 16
Like Tree1Likes
  • 1 Post By SurfMan

Thread: writing to a excel file from java program

  1. #1
    priyankabhar is offline Member
    Join Date
    Jul 2007
    Posts
    1
    Rep Power
    0

    Default writing to a excel file from java program

    Hi,

    I want to create and write to a excel file from a java program. I found a tutorial online and wrote a java file as under:

    Java Code:
    import java.io.File;
    import java.util.Date;
    import jxl.*;
    import jxl.write.*;
    
    public class jExcel{
    
    	WriteableWorkbok workbook = Workbok.createWorkbook(new File("output.xls"));
    
    	public static void main(String args[]){
    		WriteableSheet sheet = workbook.createSheet("First Sheett",0);
    
    		Label label = new Label(0,2,"A label record");
    		sheet.addCell(label);
    
    		Number number = new Number(3,4,3.1459);
    		sheet.addCell(number);
    
    		workbook.write();
    		workbook.close();
    	}
    }
    But when I compile this file, I get errors telling that package jxl does not exists and so on. Do I need to download it ? I am really new to it but I need to do the job. Please give some ideas.

    Thanks,
    Priyanka
    Last edited by JavaBean; 07-10-2007 at 08:18 PM. Reason: Code is placed inside [code] tag.

  2. #2
    mary is offline Member
    Join Date
    Jul 2007
    Posts
    51
    Rep Power
    0

    Default

    You can download from here
    SourceForge.net: Files

  3. #3
    Cortexiphan is offline Member
    Join Date
    Mar 2011
    Posts
    1
    Rep Power
    0

    Default

    When I follow the link, and I select JexcelAPI it shows me several different versions.

    Do I just download the newest one?

  4. #4
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    I'd just like to point out that any package NOT starting with one of these:
    java.
    javax.

    is a custom/community package i.e. not standard and thats why you will need to download them yourself

    also its usually best to download the latest and most stable version. look for user feedback and if the latest version doesnt have any serious bugs then you should use that one.

  5. #5
    only_java is offline Member
    Join Date
    Mar 2011
    Posts
    16
    Rep Power
    0

    Default

    For creating .xls files from java. One of the good API is jXl API.
    You can find more details from following URL
    JExcelApi

  6. #6
    basavaraj4375 is offline Member
    Join Date
    Mar 2012
    Posts
    1
    Rep Power
    0

    Default Re: writing to a excel file from java program

    Can someone please tell what is the equivalent for Label in Apache Poi???


    Thanks,
    Basavaraj

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,925
    Rep Power
    19

    Default Re: writing to a excel file from java program

    Aren't they just Cells with a cell type of CELL_TYPE_STRING?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    saaspose is offline Saaspose
    Join Date
    Jul 2012
    Location
    Lane Cove
    Posts
    39
    Rep Power
    0

    Default Re: writing to a excel file from java program

    While searching for my problem I came across your post. I know it’s a bit late but I am sure it will be useful for the other guys.To create, read and write to an excel file I would like to suggest, An Award-winning Java Excel Component that allows Java developers to embed the ability to read, write and manipulate Excel® spreadsheets (XLS, XLSX, XLSM, SpreadsheetML, CSV) EML, HTML, PDF and image file formats into their own Java applications. Some Examples with code are:

    Opening Files - Aspose.Cells for Java - Documentation - Aspose.com
    Copying and Moving Worksheets - Aspose.Cells for Java - Documentation - Aspose.com
    Save Entire Workbook into Text or CSV Format - Aspose.Cells for Java - Documentation - Aspose.com

  9. #9
    jamesbond is offline Member
    Join Date
    Sep 2013
    Posts
    1
    Rep Power
    0

    Default Re: writing to a excel file from java program

    i use simreport lib. i see it is easy to integrate into project and it is easy, quickly to understand how to generate an excel report. it can make from simple to pro report. you define the template in excel sheet and the lib keep all your format in cells (color, font, cell border, page size, header, footer...) you've define to make report. you find examples in jsimreport.com for details
    Last edited by jamesbond; 09-14-2013 at 06:27 PM.

  10. #10
    erdsingh is offline Member
    Join Date
    Jan 2014
    Posts
    4
    Rep Power
    0

    Default Re: writing to a excel file from java program

    for excel poi utility methods pls visit javabestinfo.com

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

    Default Re: writing to a excel file from java program

    Quote Originally Posted by ozzyman View Post
    I'd just like to point out that any package NOT starting with one of these:
    java.
    javax.

    is a custom/community package i.e. not standard and thats why you will need to download them yourself

    also its usually best to download the latest and most stable version. look for user feedback and if the latest version doesnt have any serious bugs then you should use that one.
    Generally, but NOT completely, look at at the org.omg.CORBA classes, the org.w3c.dom classes, and the org.xml.sax classes in the JSE.

  12. #12
    Rajendran is offline Member
    Join Date
    Jan 2014
    Posts
    1
    Rep Power
    0

    Default Re: writing to a excel file from java program

    I have worked with excel and understood reading and writing into files using documentation given here:

    JExcelApi

    Yes, It was posted by another member but i would suggest to go through example programs that come with the download. For eg , Converting excel file data into CSV files. Using formulas and such.

    If you are getting a class not found or package not found errors, You will have to set classpath to class files and packages you have downloaded through the link. Because i have complete edition of java 7 and it does not include excel file classes. I.e. I don't think classes and packages you have used in program will be available in JDK. And since you are downloading these class files and packages, You will need to set classpath for class loader to load the classes from the path you have saved them(excel manipulating classes and packages).

    Since exact error messages have not been given, I am assuming setting class path and having downloaded all class files and packages from download link should solve the issue.
    Last edited by Rajendran; 01-17-2014 at 11:55 AM.

  13. #13
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,843
    Rep Power
    5

    Default Re: writing to a excel file from java program

    Just open 'rt.jar' of the runtime in a zip tool and see what's there. Nowadays there are several third party packages (generally implementations of APIs that Oracle determines to be the reference implementation) already bundled with the JRE.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  14. #14
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    926
    Rep Power
    2

    Default Re: writing to a excel file from java program

    Quote Originally Posted by erdsingh View Post
    for excel poi utility methods pls visit javabestinfo.com
    The POI link you gave only has two examples. And they are bad ones too. For example, it doesn't account for formulas and booleans. So you might want to put in some more effort there.
    Here's a URL that contains useful examples from the creators of POI (Busy Developers' Guide to HSSF and XSSF Features).

    I normally don't comment on user-contributed sites, but in this case, I can't resist. That site makes me shudder. And I'll tell you why.

    Just a few points from the About-page:

    Don't need to write or note down the concepts
    -Yes you do, making notes and making drawings while learning stuff is important. It triggers an extra cognitive reaction from the brain which helps in learning.

    Don't need to use paper or pen to learn
    - See #1

    Every thing is available on the internet
    - Yes. That's why there are sites like RoseIndia that really mess up Java programming in general with shitty examples.

    Availability of similar related concept which comes in your mind at runtime
    - Wait, what? You just melted my brain.

    Almost everything is available which you can think of.
    - But not all is of good quality. A beginning Java developer can't tell the different between shit code and good code. That's why RoseIndia still exists.

    Solutions to the problems which are rarely found on the web.
    - Now you contradict yourself.

    From the best practice page, example B: seriously, throwing a RuntimeException when some value == null? Since when became that a Java Best Practice™?

    I don't want to bash your site, consider it constructive criticism. I appreciate that you put in the time. But if you *do* make a site, make sure the information is correct. I'm just pointing out examples where you may seriously confuse beginners with bad examples.
    gimbal2 likes this.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013

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

    Default Re: writing to a excel file from java program

    Quote Originally Posted by SurfMan View Post
    RoseIndia
    Oh the HORROR!

    That post should be rated R.

  16. #16
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,843
    Rep Power
    5

    Default Re: writing to a excel file from java program

    Yeah, rated R for Reality (check).
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Reading data from Micrsoft excel and writing to notepad
    By abhishek.jain in forum New To Java
    Replies: 4
    Last Post: 01-29-2009, 08:12 AM
  2. Replies: 0
    Last Post: 04-04-2008, 02:45 PM
  3. Help needed writing a program...
    By Francis in forum New To Java
    Replies: 2
    Last Post: 11-22-2007, 02:03 PM
  4. writing to a file
    By bugger in forum New To Java
    Replies: 1
    Last Post: 11-11-2007, 02:49 AM
  5. Poblem in Compiling a c++ file from a java program...
    By Amit Kr. Mishra in forum New To Java
    Replies: 0
    Last Post: 11-06-2007, 10:41 AM

Posting Permissions

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