NExcelAPI – a .NET port of JExcelAPI

 JExcelAPI is a neat “Java API to read, write, and modify Excel spreadsheets”, written by Andy Khan. It is very easy to use and it does a great job. Unfortunately, at work I have to deal with .NET projects as well. I thought it would be great to take advantage of the JExcelAPI’s functionality in my .NET projects too, and get rid of the Microsoft Interop crap.

Thankfully, porting JExcelAPI to .NET was a piece of cake because all source files could be easily imported into a J# class library project, and compile with nothing but slight changes. To use it, download the visual studio solution and build the class library (you will need vs 2005). If you are not familiar to JExcelAPI, you can take a glance at the Test C# project do get an idea of how it works. However, make sure that you read the tutorial. Javadoc is also available.

I want to clarify that I did nothing more than drag’n'drop the original java files into a J# project. All glory and honour goes to Andy Khan. Thank you Andy.

This entry was posted in Uncategorized. Bookmark the permalink.

4 Responses to NExcelAPI – a .NET port of JExcelAPI

  1. Danny says:

    Very cool! Thank you.

    Just… when i use the code like this:

    java.io.File templatefile = new java.io.File(“d:dokimi.xls”);
    java.io.File outputfile = new java.io.File(“d:output.xls”);
    jxl.Workbook wb = Workbook.getWorkbook(templatefile);
    WritableWorkbook wwb = Workbook.createWorkbook(outputfile, wb); //Import the xls file as a template.
    //do nothing
    wwb.write();
    wwb.close();

    it works, but i got two warning message boxes while the output xls file is opening:
    “File error:data may have been lost”
    and
    “File error. Some number formats may have been lost.”
    Cliked “OK”, the file can be opened finally.

  2. Michael Tutty says:

    This might be hard to believe but this code is still relevant. I’ve been using the jExcelAPI lib for several months and needed a .NET analog.

    For those without the J# module installed in VS.NET, you can use the following NAnt build instead:

  3. Michael Tutty says:

    (Hm, seems to have been cut off…

    This might be hard to believe but this code is still relevant. I’ve been using the jExcelAPI lib for several months and needed a .NET analog.

    For those without the J# module installed in VS.NET, you can use the following NAnt build instead:

  4. Peter says:

    Hello there!

    That is a very nice post, explains a lot. I’m with VB.NET and I’m wondering how can I add this API to my project. It should be similar right? Thing is that I did not see any DLL file over there that I could import. I found one that’s CSharpJexcel.dll that is attached to their project on sourceforge, but while doing this :

    Dim workbook As WritableWorkbook
    Try
    workbook = Workbook.createWorkbook(New File(“myfile.xls”))
    Dim sheet As WritableSheet = workbook.createSheet(“First Sheet”, 0)
    Dim label As New Label(0, 2, “R4R JExel API Example”)
    sheet.addCell(label)
    workbook.write()
    workbook.close()
    (…)

    my compiler complains that createWorkbook is not a member of WritableWorkbook. In fact it is a member of “Workbook” but then my excel would not be writable, right?

    I would really appreciate any help in this matter,

    Thank you
    Pete

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>