2

I'm using POI library to read excel sheets, xls and xlsx. I'm wondering if there is a way for me to determine what font family is used for a given cell. I'm specifically interested in determining if the font family is "symbol", where "m" is displayed as "µ". Thanks,

David

David Zhao
  • 4,284
  • 11
  • 46
  • 60

1 Answers1

6

From a Cell you can get the cell style, and from the cell style you can get the font index. Back on the workbook, you can get the font for an index and then get the font name

Code wise, you want something like:

 CellStyle style = cell.getCellStyle();
 short fontIdx = style.getFontIndex();
 Font font = workbook.getFontAt(fontIdx);
 String fontName = font.getFontName();
Gagravarr
  • 47,320
  • 10
  • 111
  • 156
  • Thanks for the answer, and I figured this out too, the challenge is to go through each and every letter in the cell to determine every font family, since text value "10 µM" can have mixed font families. – David Zhao Jan 08 '12 at 07:55
  • You should be able to use [GetIndexOfFormattingRun](http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/RichTextString.html#getIndexOfFormattingRun%28int%29) to identify where each new bit of styling starts – Gagravarr Jan 09 '12 at 10:56