A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Java
»
Other JSE/JEE APIs
Author
How to read xls, xlsx and open office excel formats from java. Any pointers ? Kindly help.
Deepak S Babu
Greenhorn
Joined: Dec 03, 2009
Posts: 1
posted
Nov 17, 2010 01:23:13
0
I used XSSF but not successful. Code Below.
While running (compilation was successful) getting as Exception in thread "main"
java.lang.NoClassDefFoundError
: org/apache/poi/ss/usermodel/Workbook
import java.io.*; import java.util.*; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class ReadFile { public static void main(String[] args) { String fileName = "C:\\Details.xlsx"; Vector dataHolder = ReadFile(fileName); read(dataHolder); } public static Vector ReadFile(String fileName) { Vector cellVectorHolder = new Vector(); try { FileInputStream arquivo = new FileInputStream(fileName); XSSFWorkbook planilha = new XSSFWorkbook(arquivo); XSSFSheet aba = planilha.getSheetAt(0); Iterator rowIter = aba.rowIterator(); while (rowIter.hasNext()) { XSSFRow myRow = (XSSFRow) rowIter.next(); Iterator cellIter = myRow.cellIterator(); Vector cellStoreVector = new Vector(); while (cellIter.hasNext()) { XSSFCell myCell = (XSSFCell) cellIter.next(); cellStoreVector.addElement(myCell); } cellVectorHolder.addElement(cellStoreVector); } } catch (Exception e) { } return cellVectorHolder; } private static void read(Vector dataHolder) { for (int i = 0; i < dataHolder.size(); i++) { Vector cellStoreVector = (Vector) dataHolder.elementAt(i); for (int j = 0; j < cellStoreVector.size(); j++) { XSSFCell myCell = (XSSFCell) cellStoreVector.elementAt(j); String stringCellValue = myCell.toString(); System.out.print(stringCellValue + "\t"); } System.out.println(); } } }
Lester Burnham
Rancher
Joined: Oct 14, 2008
Posts: 1337
posted
Nov 17, 2010 01:32:50
0
It looks like you don't have all the required POI jar files in the classpath; the missing would be named poi-3.7-20101029.jar or something like that.
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14672
11
I like...
posted
Nov 17, 2010 01:46:17
0
Welcome to the ranch !
Next time you want to post some code, please
UseCodeTags
. I'll add them for you this time.
[My Blog]
All roads lead to JavaRanch
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: How to read xls, xlsx and open office excel formats from java. Any pointers ? Kindly help.
Similar Threads
Read Excel values and store in to Database
A little help
Iterating through a String.
excel sheet data insertion
Java Code to export data to Excel
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter