开发者

Error in using getRichStringCellValue() of Apache POI

开发者 https://www.devze.com 2023-01-15 05:44 出处:网络
The following is my java code for reading a excel sheet content. String urlcnt=\"\"; for (Row row : sheet) {

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.


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();
0

精彩评论

暂无评论...
验证码 换一张
取 消