wood burning stoves 2.0*
The moose likes Other JSE/JEE APIs and the fly likes POI api to read MSExcel sheet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "POI api to read MSExcel sheet" Watch "POI api to read MSExcel sheet" New topic
Author

POI api to read MSExcel sheet

shukla raghav
Ranch Hand

Joined: Aug 03, 2008
Posts: 200
Here is a small code segment that i have extracted from a program to read MS excel file using POI api. I am getting following error messages in NetBeans at the lines i have colored corresponding to the code lines

ERROR ENCOUNTERED:
1. incompatible types
Found : org.apache.poi.hssf.usermodel.HSSFSheet.Iterator
Required : java.util.Iterator<org.apache.poi.hssf.usermodel.HSSFRow>


2. incompatible types
Found : java.util.Iterator<org.apache.poi.ss.usermodel.Cell>
Required : java.util.Iterator<org.apache.poi.[b]hssf
.usermodel.HSSFCell>

[/b]
[code]//instantiate POIFSFileSystem encapsulating inputstream
fileSystem = new POIFSFileSystem(inputStream);

//create a java usable(High level) worksheet from the POIFSFileSystem
HSSFWorkbook workBook = new HSSFWorkbook(fileSystem);

//obtain worksheet from high level WorkBook object
HSSFSheet sheet = workBook.getSheetAt(0);


//Create Iterator object to get Rows
Iterator<HSSFRow> rows = sheet.Iterator();

//Iterate to get Rows
while (rows.hasNext ())
{
//Get High Level Row Object
HSSFRow row = rows.next ();

//Display row number in the console.
System.out.println ("Row No.: " + row.getRowNum ());

//Create Iterator to get Cells
Iterator<HSSFCell> cells = row.cellIterator();


what could be the reason?

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19790
    
  20

shukla raghav wrote::
1. incompatible types
Found : org.apache.poi.hssf.usermodel.HSSFSheet.Iterator
Required : java.util.Iterator<org.apache.poi.hssf.usermodel.HSSFRow>


2. incompatible types
Found : java.util.Iterator<org.apache.poi.ss.usermodel.Cell>
Required : java.util.Iterator<org.apache.poi.[b]hssf
.usermodel.HSSFCell>

[/b]what could be the reason?

Use the API properly. HSSFSheet.iterator() returns an Iterator<Row>, not an Iterator<HSSFRow>, and Row.cellIterator() returns an Iterator<Cell>, not an Iterator<HSSFCell>. I think this will solve both your problems.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: POI api to read MSExcel sheet