Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 705
Kalpana Avatar asked Apr 23 '13 13:04

Kalpana


2 Answers

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.

like image 160
zmf Avatar answered Sep 28 '22 14:09

zmf


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.

like image 20
0x6C38 Avatar answered Sep 28 '22 13:09

0x6C38