Generate Excel Files on your website (Convert JEXcelAPI to a .Net DLL )
Introduction
What is JEXcelAPI?
JExcelApi is a Java API for reading, writing and modifying the contents of Excel spreadsheets.
Now you would argue that Microsoft already provides Office object libraries API for reading, writing and modifying excel spreadsheets. Yes, you are right. But there are certain limitations in using microsoft office objects on IIS.
You can find the info about the limitations at : http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757
So, what would you do if you want to create excel spreadsheets from your websites which are developed in ASP/ASP .Net?
Purchase
an excellent set of components from
Softartisans.
If you are looking for an open source/freeware alternative.. then.. trust me .. I've searched the web for one month and could not find a decent open source/freeware solution to the problem.
Then I stumbled upon two java based solutions... ( The following components support a limited set of the features of Microsoft excel)
1.
Jakarta POI HSSF
2.
JExcelApi
I tried to compile the Jakarta source code using Microsoft Visual J# but there were too many compiler errors. Then I tried JEXcelAPI; within an hour's effort, i compiled the java code into a .Net DLL and written some basic code in C# to test the component. It was a success.
These are the steps i followed .....
1. Download the jexcelapi source
http://www.andykhan.com/jexcelapi/jexcelapi_2_4_3.tar.gz
2. Create two folders
a. c:\jexcelapiJava
b. c:\jexcelapiNet
3. Unzip the compressed jexcelapi_2_4_3.tar.gz into c:\jexcelapiJava
4. Start Visual Studio .Net
a. Select Visual J# Projects -> Class Library
b. Save the Project as
Name: jexcel
Location: C:\jexcelapiNet
5. In Visual Studio .Net Delete Class1.jsl from the project
6. Now open the "C:\jexcelapiJava\jexcelapi\src" folder in windows explorer look at the folder structure. You'll notice that
the folder structure is as follows
common
----log
jxl
--biff
----drawing
----formula
--demo
--format
--read
----biff
--write
----biff
7. Create similar folder structre in the visual studio .Net Project we've created in Step 4 above. You can do "right click"
on the Project and select Add-> New Folder
a. as a first step create the "common" and "jxl" folders
b. then create sub folders and sub-sub folders of these folders
8. Once you are done with the folder creation, Its time to add the java files which you've downloaded and saved in
c:\jexcelapiJava (mentioned in step 3 above). You can do this by right clicking on the folder and select "Add Existing Item"
from the context menu, this will open a file dialog.. go tto the appropriate folder under "C:\jexcelapiJava\jexcelapi\src"
and select the files of that folder.
9. Save the Project.
10. Now search for the string "public static void main" in the entire project. We need to comment this function ( because we
are goint to use this as a class library). You'll find this in the jxl/demo/demo.java file.
11. Remove the following files from common/log folder
Log4JLogger.java
SimpleLoggerName.java
Log4jLoggerName.java
12. Save the project
13. Now click "Build" -> "Build Solution" from the top menu
Compiler will display lot of compiler errors... don't panic.
Look at those errors carefully , You can notice that most of those errors are about the variables which are declared but
not used in the code. (meaning -> dead variables)
The real code errors are about 5 or 6. go to the code .. if the error is "stack.clear" then change it to "stack.empty"
if you don't understand the error then comment the line (and related lines) with a retrivable comment like
"//NeedModification" so that you can carefully look at the required code modification later.
14. Once you're done with commenting the code.. click "Build" -> "Rebuild Solution" from the top menu again.
Voila
You'll get a compiler message like...
Build complete -- 0 errors, 32 warnings
Building satellite assemblies...
---------------------- Done ----------------------
Rebuild All: 1 succeeded, 0 failed, 0 skipped
15. Now go to the following folder "C:\jexcelapiNet\jexcel\bin\Debug", what do you see there? jexcel.dll
Which means.. you have a javaexcelapi .Net DLL
16. Do you want to test the dll? Right then add a
1. "Visual J# Windows application to the soultion" and set it as a startup project
2. set the references to the jexcel project
3. Add a button to the form and double click it. this will lauch the code window.
4. try example code from the jexcelapi code downloaded
Happy coding
PS: Don't forget to modify the commented code. and if you have done successful modification and testing.. send the code to me
:)