且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-08-24 21:40:52

根据评论编辑

您可以参考XSSFCellStyle,从中你可以得到 XSSFFont.使用它你可以获得 XSSFColor, getFontName() 或 getFamily()getFontHeight()getFontHeightInPoints().

You can refer to XSSFCellStyle, from it you can get the XSSFFont. Using that you can get XSSFColor, getFontName() or getFamily() and getFontHeight() or getFontHeightInPoints().

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

Based on example cell that I've used:

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