I am trying to read data from database and then need to write the data to an excel/csv file in an java application. The data from database can be more than 10000 rows. So could someone suggest a nice solution taking into account the performance issue also.
Is there a way we can directly read and write to excel sheet.
Thanks in advance,
Kathy.
You can use Apache POI to do this: http://poi.apache.org
Use the HSSFWorkbook as an abstraction of a .xls workbook. There's also a XSSF format for the newer XML-based Excel files (.xlsx, etc).
Apache POI will best suits to your problem.
Try the following references example and document.
http://poi.apache.org/
http://viralpatel.net/blogs/java-read-write-excel-file-apache-poi/
The second reference will give you the whole implementation of how to work with POI.
When it comes to java excel you should try out Apache POI.
Apache has a nice library that should meet your requirements.
Look into http://poi.apache.org/
Hope this helps.
Related
Everyone, I have some 10 pdf file (No Tables in this files) and i need to convert to Excel.
Is there a way to convert to Excel?
By Googling, Using Apache Poi/aspose we can achieve this. but I am not getting proper way(Code link) for this.
How can I do this using Apache POI/aspose. Any help, suggestion is highly appreciated. Thanks
It seems that the only possible way to do this is using Aspose. Thought we can read the PDF using PDFBox kind of library and write to the excel using apache POI or etc will break the formatting. If we want to convert PDF to Excel with the formatting we need to use aspose.
http://www.aspose.com/
This is a commercial product but you can use the trial version to test your requirement.
http://www.aspose.com/docs/display/pdfjava/Convert+PDF+to+Excel+Workbook
Thanks
Does anyone knows if I can specify the name(s) of the sheets that I want to read using Apache Poi?
Right now I'm using a for to read all sheets in a workbook.
Ok, so to answer the question and save you a lot of time...
Yes, it is possible and can be easily done via getSheet(java.lang.String name) on the org.apache.poi.ss.usermodel.Workbook.
As a side note I'd strongly suggest going through POI Busy Developers' Guide and the API documentation, as it's a really powerful library which familiarity with can save you a lot of time in the future.
I want to open an Excel file in browser using java 1.6. If I have changed excel sheet cell value then it will reflect on original excel file...
How to do this?
I have used the POI libary from Apache (http://poi.apache.org/) to create/manipulate .xls in the past quite successfully.
I shall recommend to use JExcel API. I guess it is more convenient to use.
Probably this post will help you to decide between POI and JExcel: http://java.itags.org/java-tools/122717/
I have a directory where files are constantly updated. I need to read the latest excel file and convert it into tab delimited file. It is under windows. A batch + java solution will work for me. Or if I can use excel in command line programatically that also works
I would disagree with those people who recommend Apache POI. The best API that I know of for dealing with Excel is Andy Khan's JExcel.
It has already been widely suggested, POI is probably the most complete "pure Java" implementation of Excel.
In one API you get support for Excel 2003 and 2007.
However, you need to be weary of its memory footprint. It is a hog. If you use it, make sure you use the event-driven model it supports as this will reduce footprint and execute faster.
In Java you can use, for example, Apache POI library to read data from Excel files. And then use standard Java facilities to write data into tab delimited file.
You can read in the excel sheet using POI and then iterate through the cells, writing them out to a separate file with appropriate delimiters.
Have a look at other SQ question: convert Excel to csv either using shell script or jython . if so how
I answered with PyODConverter, but there is jodconverter: Java version of this tool. It uses OpenOffice working as a service. I use it to convert between various file formats.
You can use Apache POI API for reading the excel file and OpenCSV for writing the CSV file.
I am very new to java. I am trying to fetch some data from a database and the result set is displayed in excel. I am able to inetract with database. But how should I go ahead for inserting data into excel sheet.Its simple Java program and in future I would like to generate files in other format say PDF, doc etc.
I am looking for an approach with lesser load on CPU, faster.
thanks in advance for help.
Just spit out a CSV file. It's lightweight and portable. You can grab a csv writer from Apache commons I think but spending the 10 min it would take to write one might be a good learning exercise as well.
If you want a real solution where you want different outputs (eg excel, pdf, rich text etc) then use a reporting tool. There are plenty of opensource tools like ireport which will let you create a template then write a simple java app that renders that to pdf, excel etc. Otherwise you will end up doing it by hand. It's a bit heavyweight but anything more than trival tabular output will be easier.
Apache POI is for you in this case, but you will find it a little bit overwhelmed if you just need to write/read data from an excel file.
Try jExcel instead, the API is simple and straightforward, you can also manipulate sheets within an excel workbook.
The easiest and standard way of doing this is to use POI library:
http://poi.apache.org/spreadsheet/quick-guide.html
The new xlsx format is based on Open-XML and would provide a method of generating these files without any dependency on Microsoft-office COM libraries -- the same could done for docx and pptx formats later, as well as other open-Xml formats like EPUB.
The Apache POI project looks like it might provide one possible solution. There's also an article on the MSDN interop blog that discusses this in some detail.
The key words you should google for are OLE and DDE.
Though, Java is not the best language for interface Microsoft's software.
for generating excel i think you should try simreport in jsimreport.com. in my opinion, it's quite simple to make an excel report, it uses the excel sheet to generate report so easy to config and visually