Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java API
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Jeanne Boyarsky
Ron McLeod
Sheriffs:
Paul Clapham
Liutauras Vilda
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Other JSE/JEE APIs
How to read xls, xlsx and open office excel formats from java. Any pointers ? Kindly help.
Deepak S Babu
Greenhorn
Posts: 1
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 1337
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 14691
16
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
if you think brussel sprouts are yummy, you should try any other food. And this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
A little help
Iterating through a String.
Java Code to export data to Excel
Read Excel values and store in to Database
excel sheet data insertion
More...