是否可以使用apache POI库确定excel单元格中使用的字体系列

时间:2021-02-04 20:26:06

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,

我正在使用POI库来读取Excel工作表,xls和xlsx。我想知道是否有办法让我确定给定单元格使用的字体系列。我特别感兴趣的是确定字体系列是否为“符号”,其中“m”显示为“μ”。谢谢,

David

1 个解决方案

#1


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

从Cell中可以获得单元格样式,从单元格样式中可以获得字体索引。回到工作簿,您可以获取索引的字体,然后获取字体名称

Code wise, you want something like:

代码方面,您需要以下内容:

 CellStyle style = cell.getCellStyle();
 short fontIdx = style.getFontIndex();
 Font font = workbook.getFontAt(fontIdx);
 String fontName = font.getFontName();

#1


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

从Cell中可以获得单元格样式,从单元格样式中可以获得字体索引。回到工作簿,您可以获取索引的字体,然后获取字体名称

Code wise, you want something like:

代码方面,您需要以下内容:

 CellStyle style = cell.getCellStyle();
 short fontIdx = style.getFontIndex();
 Font font = workbook.getFontAt(fontIdx);
 String fontName = font.getFontName();