What is the difference between getRichStringCellValue() and getStringCellValue() methods of POI HSSFCell class?

强颜欢笑 提交于 2019-12-10 14:24:51

问题


I am trying to read data stored in a Excel sheet using Java POI. I am confused with these two methods because both methods reutrn string value stored in the cell. Could anyone explain the difference between these two methods?


回答1:


The important clue is to look @ the documentation and note the different return types.

getRichStringCellValue() returns the type of XSSFRichTextString while getStringCellValue() returns a plain old java String.

You probably only want to use getStringCellValue(), unless you're doing something like copying a spreadsheet and wish to retain any formatting. If that's the case, the XSSRichTextString object that is returned by getRichStringCellValue() will contain any format information like bold or italic.




回答2:


From Apache's Documentation:

getRichStringCellValue():

get the value of the cell as a string - for numeric cells we throw an exception. For blank cells we return an empty string. For formulaCells that are not string Formulas, we throw an exception.

getStringCellValue():

get the value of the cell as a string - for numeric cells we throw an exception.



来源:https://stackoverflow.com/questions/16170275/what-is-the-difference-between-getrichstringcellvalue-and-getstringcellvalue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!