Kalpana
Kalpana

Reputation: 561

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?

Upvotes: 5

Views: 13696

Answers (2)

zmf
zmf

Reputation: 9313

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.

Upvotes: 11

0x6C38
0x6C38

Reputation: 7076

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.

Upvotes: 6

Related Questions