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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With