• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

How to read .xlsx Excel files in Java: can find Sheet and Workbook  RSS feed

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to access Excel Sheet .xlsx files in Java. I have tried various options available from internet. My program is using following jar files:

poi-ooxml-3.5-beta4.jar,
openxml4j-1.0-beta.jar

I have done following imports:



I am getting error in the following code:



For Sheet, I am getting following error messages:
cannot find symbol
symbol: class Sheet

For Workbook, I am getting following error messages:

cannot find symbol
symbol: class Workbook

no suitable method found for create (String)
method WorkbookFactory.create(POIFSFileSystem) is not applicable
(argument mismatch; String cannot be converted to POIFSFileSystem)
method WorkbookFactory.create(Package) is not applicable
(argument mismatch; String cannot be converted to Package)
method WorkbookFactory.create(InputStream) is not applicable
(argument mismatch; String cannot be converted to InputStream)

Some body please guide me.

Zulfi.
 
author & internet detective
Sheriff
Posts: 38571
660
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did it compile when you had this uncommented? (in particular, could it find the Workbook class)

import org.apache.poi.ss.usermodel.Workbook;

If not, how are you running this? Command line? Build tool?
 
Zulfi Khan
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
When lines containing classes i.e. Sheet and  Workbook are uncommented, NetBeans  give compilation error. Otherwise when the lines are commented, Netbeans does not give any error. But then there is nothing to run.  I am using NetBeans IDE. I have attached the pictures.

Some body please guide me.
Zulfi.
After-commenting.jpg
[Thumbnail for After-commenting.jpg]
Before-commenting.jpg
[Thumbnail for Before-commenting.jpg]
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 38571
660
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
next is to check
1) Are the two jars you mentioned on your NetBeans classpath?
2) Does one of them contain the Sheet/Workbook classes? (If not, I bet you need poi.jar)
 
Master Rancher
Posts: 3631
40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


When you uncomment that first line does it give an error?

Do the other two lines give any errors?
 
Zulfi Khan
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I can accept that it helped me. I really helped me. I removed the asterisk import. Got confusion between NetBeans classpath and project classpath and found that lib directory was important which was not part of my project. When I created this by going through project properties and then clicking on libraries. Initially the text field of “Libraries Folder” was grey but then I did something which now shows the black text on the text field and the compile time libraries by copying their names from my jar folder. With these two all my import errors and Workbook and Sheet error got removed but then I added one more jar: poi-3.17.jar as told by you.

However, I am still getting one error (i.e. symbol not found getCellString( )??? on the following line)

rowData[j] = cell == null ? null : getCellString(cell);

Some body please guide me.

Zulfi.
Sheet-and-Workbook-without-error.jpg
[Thumbnail for Sheet-and-Workbook-without-error.jpg]
imports-without-error.jpg
[Thumbnail for imports-without-error.jpg]
 
Zulfi Khan
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I can accept that it helped me. I removed the asterisk import..... (Extra Sentence removed)

Zulfi.
 
Dave Tolls
Master Rancher
Posts: 3631
40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't post images of code.
It's a lot easier for us if you post the code (in code tags).

I don't see that line in your images.
Where is the getCellString method defined?
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you want tp read excel file to the table or export it i can help
 
Zulfi Khan
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks everybody.

Dave you are right. I found the definition of getCellString(..) method. Initially I though that it was built in method.

However, now I am getting problem in adding in the arraylist 'data' after retrieving the contents of each cell of each row. This program is storing the data of each cell of each row in rowData[ ] which is an array of String. After that it is storing rowData in an arrayList 'data'. Its giving me error at this point 'Cannot find symbol data(String[]).



The complete code is given below:


Some body please guide me.

Zulfi.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!