如何在Java,Apache POI中获取Excel的单元格字段的字体样式? [英] How to get the font style of a cell field of excel in Java, Apache POI?
本文介绍了如何在Java,Apache POI中获取Excel的单元格字段的字体样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Java中的excel中捕获单元格字段的字体.我正在使用Apache POI.如果可能的话,我想捕获font-color
,font-family
,font-weight
,font-size
等.
I would like to capture the font of a cell field in excel in Java. I am using Apache POI. If possible, I would like to capture font-color
, font-family
, font-weight
, font-size
, etc.
我该如何实现?
推荐答案
基于评论进行了编辑
您可以参考 XSSFCellStyle ,从中可以获得 XSSFFont .使用它可以获取 XSSFColor , getFontName()或 getFamily()和 getFontHeight()或
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
这篇关于如何在Java,Apache POI中获取Excel的单元格字段的字体样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文