我想用Java捕获Excel中单元格字段的字体。我正在使用 Apache POI。如果可以的话我想捕捉font-color
, font-family
, font-weight
, font-size
, etc.
我怎样才能实现这个目标?
根据评论进行编辑
您可以参考XSSF单元格样式 http://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFCellStyle.html,从中你可以得到XSSFFont https://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFFont.html。使用它你可以得到XSSF颜色 http://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFColor.html, 获取字体名称() https://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFFont.html#getFontName() or 获取家庭() https://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFFont.html#getFamily() and 获取字体高度() https://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFFont.html#getFontHeight() or getFontHeightInPoints() https://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFFont.html#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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)