views:

14

answers:

1

The following is my java code for reading a excel sheet content.

String urlcnt="";
for (Row row : sheet) {
 {
Cell firstCell = row.getCell(0);
urlcnt=firstCell.getRichStringCellValue();}

While compiling the above code am getting the following error.

ReadExcel.java:18: incompatible types
found   : org.apache.poi.ss.usermodel.RichTextString required: java.lang.String
                    urlcnt=firstCell.getRichStringCellValue();//This line is the cause for the error

Instead of storing the getRichStringCellValue() in a string, if I just print the value of the cell, it works fine. But I go ahead and store it in a string for further processing the problem occurs.

Kindly let me know what has to be done to proceeed.

+1  A: 

The error is because getRichStringCellValue() returns a HSSFRichTextString or XSSFRichTextString (depending on whether your cell is HSSFCell or XSSFCell) and you are assigning it to a String

Depending on your further processing -

Do you want to call applyFont or clearFormatting on the HSSFRichTextString ? then store it in a HSSFRichTextString/XSSFRichTextString.

If you actually want only the String text, use the getString() method from the POI API

UPDATE as per your comments

Use it as

urlcnt=firstCell.getRichStringCellValue().getString();
JoseK
Can you be little more explanatory? how to store it in a HSSFRichTextString?
LGAP
I want the String text alone. Further processing just includes comparing the string with the DB and adding it in the DB.
LGAP
Thanks JoseK.. Now its perfect. Thanks again :)
LGAP