如何在Java,Apache POI中获取excel单元格字段的字体样式? [英] How to get the font style of a cell field of excel in Java, Apache POI?

查看:184
本文介绍了如何在Java,Apache POI中获取excel单元格字段的字体样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Java 中捕获 Excel 中单元格字段的字体.我正在使用 Apache POI.如果可能,我想捕获 font-colorfont-familyfont-weightfont-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.

我怎样才能做到这一点?

How can I achieve this?

推荐答案

根据评论编辑

您可以参考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

这篇关于如何在Java,Apache POI中获取excel单元格字段的字体样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆