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.
Related
I want to write some java code to read, write, edit and do other things with sets of Microsoft Word files (different Word versions). What is the best API for this, and how do I get started?
P.S. I searched StackOverflow and found that this question has been asked before, but several years ago. I would like to know the best available API today. Thanks.
Check out apache POI : https://poi.apache.org/
As quoted on their website.. "Apache POI - the Java API for Microsoft Documents"
Personally I have only used this for EXCEL spreadsheet manipulation, but it does support word documents as well...
The best part is it's open source and completely free!
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.
I has a excel file with 4 excel sheets in it. Now i want to read or write to required excel sheets using java without using any third party lib.
I know i can read and write data using FileInputStream and FileOutputStream respecitvely. But i can handle the work sheets??
No, you can'not, There is numerous way in Java for reading/writing files, but there is no built-in support for MS Office/Excel spreadsheets. http://poi.apache.org/ - is a key to victory.
If your goal is to interface with data from an excel sheet from your Java application, I'd suggest to use the solutions suggested by other posters, it will save you a lot of work.
If, however, you want to be able to read excel files from Java (or any other programming language for that matter) 'just because you can' then you could take a look at this file and read the instructions on this web-page. I would warn you that it would take considerably more time to implement your own API if you base it only on the file-specs that are publicly available. You might want to check out the work done by the people from the Apache POI project to get an idea of how to approach it. Or (even better) contribute to the project. Here you can find out how to go about doing that
I have been using Apache POI for quite sometime and it works great but I am not able to find a reliable answer about filter support in the library.
For reference, I mean the filter option available in data tab in excel which allows you to show all unique values of a column as a combo box in the header of the Column.
I know there is already a question about it generate excel in java where this question was asked.
And I see that Apache POI people checked in something recently for this
https://issues.apache.org/bugzilla/show_bug.cgi?id=35125
Is there anyone who has used POI new version to try filter option?
As waiting for the final release of POI with this feature may not be possible for us, can anyone point out other Excel Java API which allow this option (JExcel does not as far as I found out). I do see many websites allowing export to excel with filtering available. If there is no good API to provide it, is there any other way or post processing on excel which i can do to add this option
Sorry for the repeated question, but I could not see any other way to resolve my issue other than approaching stackoverflow community
It's already enabled in Apache POI 3.7. How? take a look...
sheet.setAutoFilter(CellRangeAddress.valueOf("A1:C200"));
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