Java 使用Apache POI的getRichStringCellValue()时出错

Java 使用Apache POI的getRichStringCellValue()时出错,java,excel,apache-poi,Java,Excel,Apache Poi,下面是我用于读取excel工作表内容的java代码 String urlcnt=""; for (Row row : sheet) { { Cell firstCell = row.getCell(0); urlcnt=firstCell.getRichStringCellValue();} 在编译上述代码时,我遇到以下错误 ReadExcel.java:18: incompatible types found : org.apache.poi.ss.usermodel.RichText

下面是我用于读取excel工作表内容的java代码

String urlcnt="";
for (Row row : sheet) {
 {
Cell firstCell = row.getCell(0);
urlcnt=firstCell.getRichStringCellValue();}
在编译上述代码时,我遇到以下错误

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
与其将getRichStringCellValue()存储在字符串中,不如只打印单元格的值,这样就可以了。但我继续将其存储在字符串中,以便在出现问题时进行进一步处理


请告诉我必须执行的操作。

错误是因为
getRichStringCellValue()
返回or(取决于您的单元格是HSSFCell还是XSSFell),并且您正在将其分配给
字符串

根据您的进一步处理-

是否要在HSSFRichTextString上调用
applyFont
clearFormatting
? 然后将其存储在HSSFRichTextString/XSSFRichTextString中

如果您实际上只需要字符串文本,请使用POI API中的方法

根据您的评论进行更新

把它当作

urlcnt=firstCell.getRichStringCellValue().getString();

你能再解释一下吗?如何将其存储在HSSFRichTextString中?我只需要字符串文本。进一步的处理只包括将字符串与数据库进行比较并将其添加到数据库中。谢谢JoseK。。现在它完美了。再次感谢:)