如何在Java,Apache POI中获取excel单元格字段的字体样式?

Bij*_*yan 3 java excel fonts apache-poi

我想在 Java 中捕获 excel 中单元格字段的字体。我正在使用 Apache POI。如果可能的话,我想捕捉font-colorfont-familyfont-weightfont-size,等。

我怎样才能做到这一点?

Man*_*ian 6

根据评论编辑

你可以参考XSSFCellStyle,从中你可以得到XSSFFont。使用它您可以获得XSSFColorgetFontName()getFamily()getFontHeight()getFontHeightInPoints()

基于我使用过的示例单元格:

XSSFCellStyle cs = cell.getCellStyle();
XSSFFont font = cs.getFont();

//Getting Font color
XSSFColor color = font.getXSSFColor();
System.out.println("Font color : " + color.getARGBHex());
//==>   FF00B0F0

//Getting Font name
System.out.println("Font name : " + font.getFontName());
//==>   Arial

//Getting Font family name
FontFamily family = FontFamily.valueOf(((XSSFFont) font).getFamily());
System.out.println("Font family : " + family);
//==>   SWISS

//Getting Font family int
System.out.println("Font family in int : " + font.getFamily());
//==>   2

//Getting Font height
System.out.println("Font FontHeight : " + font.getFontHeight());
//==>   280

//Getting Font height in point
System.out.println("Font height in point : " + font.getFontHeightInPoints());
//==>   14

//Getting Font bold weight  
System.out.println("Font BoldWeight : " + font.getBoldweight());
//==>   700
Run Code Online (Sandbox Code Playgroud)