Friday, November 27, 2009

Read Data from Excel File

I am sure some of us have come across the requirement of reading through excel files. The following program reads a Excel file. It basically parses through all the cells and determines if it is a String or a Number or just white spaces.

  1. I basically used Apache POI API to read Excel files.
  2. Download and extract the following zip file: http://www.apache.org/dyn/closer.cgi/poi/release/bin/poi-bin-3.5-FINAL-20090928.zip
  3. Put poi-3.5-FINAL-20090928.jar in classpath (Environment Variables in Windows OR Bashrc file in Linux-Ubuntu OR External Jar in Eclipse).
  4. Compile and Execute the following code with small changes(change the name of the file to be read to your own Excel Sheet).
  5. The code determines if the data read from the cell is a number or a string.
  6. It doesnt convert the number to a string by default. You have to convert it manually.

IMPORTANT POINT:
Apache POI API has no support to read Number seperately (like a method readString() or readNumber()), as EXCEL Spread Sheet does contain most of the time digits and numbers.



Reference:

http://www.kodejava.org/examples/461.html

No comments:

Post a Comment