• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

POI api to read MSExcel sheet

 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
This tiny ad will self destruct in five seconds.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic