• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 950
  • Last Modified:

How to read xls or cvs file in java


How to read xls or cvs file in java ?
Sathish David  Kumar N
Sathish David  Kumar N
5 Solutions
Two different things: xls is a binary format:


A csv file is a text file and can be read using standard Java or a  csv reader, such as Ostermiller CSVReader or OpenCSV
Excel (xls) files can be dealt with like database tables using a JDBC driver, for example, this one: http://xlsjdbc.sourceforge.net/
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

1) CSV files can be processed using standard java string processing. You will have to consider field delimeter, date format etc., but they are forms of text processing only.

2) Binary XLS files can be processed using the very useful Java APIs provided by Apache POI project. POI is very comprehensive and covers different types of Microsoft documents. For processing XLS, you will only need a small area in POI, called HSSF.

a) http://poi.apache.org/
b) http://poi.apache.org/spreadsheet/index.html

There is standard javadoc available on whole POI at http://poi.apache.org/apidocs/index.html . You will on ly need to focus on those prefixed by HSSF, starting with HSSFWorkbook.
Bruce SmithSoftware Engineer IICommented:
@subratabiswas is correct. Probably the most versatile tool that I've used to read/write .xls files via Java. The site there at poi.apache.org offers many examples and is fairly easy to implement.

There is a decent tutorial here (http://www.javabeat.net/articles/41-apache-poi-reading-excel-sheet-using-java-1.html) of how to read an Excel spreadsheet so that you can see if this might work for you before you actually download the POI api and 'get your hands dirty'.

Also, be sure to read the limitations before you begin: http://poi.apache.org/spreadsheet/limitations.html

PS: Don't let the acronyms scare you though:
POI = "Poorly Obfuscated Implementation"
HSSF = "Horrible SpreadSheet Format"
you should be able to find what you need to use POI here
Sathish David Kumar NArchitectAuthor Commented:

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now