I am looking for the possibility of creating an excel file from a query that a user may generate on our database, so that the user can download it.
Currently we have results displaying to the GUI, but I am wondering what is the best way to create the excel file with the data returned. I'm using a MySQL DB, java JAxRS, JavaScript & html5.
Any suggestions are very welcome.
As javadev mentioned, Apache POI is one of the best approach I would also suggest. Here is an example code that suits your requirement. Hope this would help.
I highly recommand to use Apache POI API
Here is a good tutorial to start.
Related
I have an Excel with some macros. The data is currently sourced manually. In order to automate the report, I need to source the data directly from Oracle database. Unfortunately, this cannot be done, as it is a production database and passwords cannot be shared with anyone.
The next best possible approach is to connect via the Java layer. How can I connect VBA with a Java service?
Any conceptual starting points will also be appreciated.
There is a very nice API from Apache called POI for processing Microsoft documents. http://poi.apache.org/
The other approach is to use OLEDB driver for Excel which will allow you to read data from Excel exactly as you will do from any database using JDBC.
Interop between different technologies likes this is commonly achieved with a combination http and xml.
It's a long time since I saw this done so the technologies might be out of date but you can create a ADO record set from XML.
Excel can make a http call to a Java server that returns the xml. This xml can then be used to create a record set for Excel to consume just as if that record set were obtained directly from the database.
guys. In our project, we need to add a new feature which is to export some test result data into PDF and Word format file for user. The structure of test result data in our system is generally simple 2D table (some may be a little complex that has cell consolidation). Is there any stable and mature java open source solution for this? Or should we use any report solution like BIRT (but we feel such solution may be too heavy weight for this feature)? Because the deadline of this project is tough, to save some investigation time I post a question here and want to get some suggestions. Any suggestion will be very appreciated, thanks. By the way, our project is a Swing application.
JasperReports allow export to PDF and DOC, it might be easier than using POI and iText.
As time is short and this is a new feature, you might temporize by writing a comma-separated-value file with a name acceptable to Excel. At a later time, implement a more robust solution using Apache POI or something similar that your research identifies.
I have a set of complex Excel files (with figures in it) that I want to show in a web browser. So I need to convert them into HTML page first. Since the excel files are very complex, I can not just parse them and generate a HTML table with HTML tags. The current manual solution that works fine is when I use Microsoft Excel software to save the spreadsheet as a HTML page. I want to automate this task in some way since I want to do it progrmatically through Java. Is their any existing solution or a way to do it? Thanks.
EDIT - I was able to create a macro for it but could not figure it out that how can I execute a macro on excel file from a Java program. Does somebody know?
If open office does a good job of the export then you could take a look at the source to see how it does it. OO is a combination of Java and C++ I believe so you might get lucky and find a Java solution.
Otherwise, I would try and use Excel itself to do the export and find some way of calling it programmatically. If you go down this path you'd be better of using a Microsoft stack (C# would be the most similar to Java) as I would expect it to have all the functions you need already defined.
You might look into POI:
http://poi.apache.org/
I think your best bet is to call Excel from Java using JACOB
Creating direct COM calls (which is what you'll be doing from JACOB) is a bit tough, but you'll get the hang of it. I can't imagine that the Excel VBA macro is horribly complicated. Take a look at the sample code (Usage and Documentation) in the JACOB link for what this will look like.
One other thing: Remember to explicitly clear references. JACOB will release COM handles when objects are garbage collected, but if you are doing any sort of high performance work, you will want to close those connections as quickly as possible. We generally write all of our COM code in a series of try/finally statements - the code is messy, but robust.
Try using hypernumbers. (Disclaimer, I'm the CEO)
I ended up using the Scribd API. I uploaded the document to their server through their API in realtime and pasted an iframe with a link in it which is returned by Scribd.
has anybody found a library that works well with large spreadsheets?
I've tried apache's POI but it fails miserably working with large files - both reading and writing. It uses massive amounts of memory leaving you needing a supercomputer to parse or create a 20+mb spreadsheet.
Surely there is a more memory efficient way and someone has written it?!
#pstanton..
I was working on a similar solution and was able to write large excel 2007 files with hundreds of rows exported from database. Here is the link to it:
http://vikramvkamath.blogspot.com/2010/07/writing-large-excel-files-excel-2007.html
My solution is an extension on Yegor Koslov's SheetWriter class follow this http link and it works very well for me.
Let me know in case you face any issues.
~Vikram
I cannot really recommend a library to you. But when you need the best performance, it might be worth a try to go to the people who came up with Excel in the first place. I guess the APIs that are available from .NET are much more efficient in handling Excel files. So the idea would be to implement a web service or similiar component in .NET that does most of the Excel-related grunt work for you and just invoke that from Java.
This is basically the same idea as Jannik's, but you use the Java COM Bridge to access the Excel APIs directly from Java. We have had good success doing this with Word. Obvious downside is that it only works on Windows.
Have you tried JExcelAPI as an alternative to POI ? I confess I can't comment on it's memory efficiency.
at time of posting, there is no pure java scalable solution for reading and writing large excel files.
May be CSV file format can help you. You just need to seperate each value by comma and save file with .csv extension.
Can anyone give me some idea about uploading data from excel to access database using java
You'll definitely want to check out Apache POI - Java API To Access Microsoft Format Files. You'll likely find the Excel bindings you need there. For MS Access, you'll want a JDBC Driver which you can find on Sun's website. Then you can just write the glue code.
Why would you want to use Java for that? You can link Excel and Access data directly:
http://office.microsoft.com/en-us/access/HP010950951033.aspx
I've used POI before to read and write Excel files. Once you got the data, use JDBC (maybe the JDBC/ODBC bridge) to load it into Access.