java-POI的Excel默认字体和样式
2022/3/21 17:57:50
本文主要是介绍java-POI的Excel默认字体和样式,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
java中POI的Excel内置字体和样式
java版poi内置的Font和CellStyle,本来以为是没有的,通过代码测试 发现有还不一样。
POM引用
<poi.varsion>3.17</poi.varsion> <!--xls 解析生成--> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>${poi.varsion}</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>${poi.varsion}</version> </dependency>
代码
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; /** * Test2Main 类说明: * * @version v1.0 * @date 2022/3/21 */ public class Test2Main { public static void main(String[] args) { try{ HSSFWorkbook hssfWorkbook = new HSSFWorkbook(); test(hssfWorkbook,"hssf"); XSSFWorkbook xssfWorkbook = new XSSFWorkbook(); test(xssfWorkbook,"xssf"); }catch (Exception e){ e.printStackTrace(); } } public static void test(Workbook workbook,String name){ short fontSize = workbook.getNumberOfFonts(); System.out.println(name + ",默认字体个数:" +fontSize); System.out.println("index\tcolor\titalic\tfontName\tunderline\tbold\tstrikeout\ttypeOffset"); for (short i = 0; i < fontSize; i++) { Font font = workbook.getFontAt(i); System.out.print(font.getIndex() + "\t"); System.out.print(font.getColor() + "\t"); System.out.print(font.getItalic() + "\t"); System.out.print(font.getFontName() + "\t"); System.out.print(font.getUnderline() + "\t"); System.out.print(font.getBold() + "\t"); System.out.print(font.getStrikeout() + "\t"); System.out.println(font.getTypeOffset()); } int styleSize = workbook.getNumCellStyles(); System.out.println(name + ",默认样式个数:" +styleSize); System.out.println("1\t2— —\t3— —\t4— —\t5— —\t6— —\t7— —\t8— —\t9\t10— —\t11\t12\t13— —\t14\t15— —\t16\t17\t18\t19\t20\t21— —\t22— —\t23\t24"); for (int i = 0; i < styleSize; i++) { CellStyle style = workbook.getCellStyleAt(i); //1 System.out.print(style.getIndex() + "\t"); //2 System.out.print(style.getLocked() + "\t"); //3 System.out.print(style.getQuotePrefixed() + "\t"); //4 System.out.print(style.getAlignmentEnum() + "\t"); //5 System.out.print(style.getBorderBottomEnum() + "\t"); //6 System.out.print(style.getBorderLeftEnum() + "\t"); //7 System.out.print(style.getBorderRightEnum() + "\t"); //8 System.out.print(style.getBorderTopEnum() + "\t"); //9 System.out.print(style.getBottomBorderColor() + "\t"); //10 System.out.print(style.getVerticalAlignmentEnum() + "\t"); //11 System.out.print(style.getFillBackgroundColor() + "\t"); //12 System.out.print(style.getFillForegroundColor() + "\t"); //13 System.out.print(style.getFillPatternEnum() + "\t"); //14 System.out.print(style.getFontIndex() + "\t"); //15 System.out.print(style.getHidden() + "\t"); //16 System.out.print(style.getIndention() + "\t"); //17 System.out.print(style.getLeftBorderColor() + "\t"); //18 System.out.print(style.getRightBorderColor() + "\t"); //19 System.out.print(style.getTopBorderColor() + "\t"); //20 System.out.print(style.getRotation() + "\t"); //21 System.out.print(style.getShrinkToFit() + "\t"); //22 System.out.print(style.getWrapText() + "\t"); //23 System.out.print(style.getDataFormat() + "\t"); //24 System.out.println(style.getDataFormatString()); } } }
日志
hssf,默认字体个数:4 index color italic fontName underline bold strikeout typeOffset 0 32767 false Arial 0 false false 0 1 32767 false Arial 0 false false 0 2 32767 false Arial 0 false false 0 3 32767 false Arial 0 false false 0 hssf,默认样式个数:21 1 2— — 3— — 4— — 5— — 6— — 7— — 8— — 9 10— — 11 12 13— — 14 15— — 16 17 18 19 20 21— — 22— — 23 24 0 true false GENERAL NONE NONE NONE NONE 0 BOTTOM 64 64 NO_FILL 0 false 0 0 0 0 0 false false 0 General 1 true false GENERAL NONE NONE NONE NONE 0 BOTTOM 64 64 NO_FILL 1 false 0 0 0 0 0 false false 0 General 2 true false GENERAL NONE NONE NONE NONE 0 BOTTOM 64 64 NO_FILL 1 false 0 0 0 0 0 false false 0 General 3 true false GENERAL NONE NONE NONE NONE 0 BOTTOM 64 64 NO_FILL 2 false 0 0 0 0 0 false false 0 General 4 true false GENERAL NONE NONE NONE NONE 0 BOTTOM 64 64 NO_FILL 2 false 0 0 0 0 0 false false 0 General 5 true false GENERAL NONE NONE NONE NONE 0 BOTTOM 64 64 NO_FILL 0 false 0 0 0 0 0 false false 0 General 6 true false GENERAL NONE NONE NONE NONE 0 BOTTOM 64 64 NO_FILL 0 false 0 0 0 0 0 false false 0 General 7 true false GENERAL NONE NONE NONE NONE 0 BOTTOM 64 64 NO_FILL 0 false 0 0 0 0 0 false false 0 General 8 true false GENERAL NONE NONE NONE NONE 0 BOTTOM 64 64 NO_FILL 0 false 0 0 0 0 0 false false 0 General 9 true false GENERAL NONE NONE NONE NONE 0 BOTTOM 64 64 NO_FILL 0 false 0 0 0 0 0 false false 0 General 10 true false GENERAL NONE NONE NONE NONE 0 BOTTOM 64 64 NO_FILL 0 false 0 0 0 0 0 false false 0 General 11 true false GENERAL NONE NONE NONE NONE 0 BOTTOM 64 64 NO_FILL 0 false 0 0 0 0 0 false false 0 General 12 true false GENERAL NONE NONE NONE NONE 0 BOTTOM 64 64 NO_FILL 0 false 0 0 0 0 0 false false 0 General 13 true false GENERAL NONE NONE NONE NONE 0 BOTTOM 64 64 NO_FILL 0 false 0 0 0 0 0 false false 0 General 14 true false GENERAL NONE NONE NONE NONE 0 BOTTOM 64 64 NO_FILL 0 false 0 0 0 0 0 false false 0 General 15 true false GENERAL NONE NONE NONE NONE 0 BOTTOM 64 64 NO_FILL 0 false 0 0 0 0 0 false false 0 General 16 true false GENERAL NONE NONE NONE NONE 0 BOTTOM 64 64 NO_FILL 1 false 0 0 0 0 0 false false 43 _(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_) 17 true false GENERAL NONE NONE NONE NONE 0 BOTTOM 64 64 NO_FILL 1 false 0 0 0 0 0 false false 41 _(* #,##0_);_(* (#,##0);_(* "-"_);_(@_) 18 true false GENERAL NONE NONE NONE NONE 0 BOTTOM 64 64 NO_FILL 1 false 0 0 0 0 0 false false 44 _("$"* #,##0.00_);_("$"* (#,##0.00);_("$"* "-"??_);_(@_) 19 true false GENERAL NONE NONE NONE NONE 0 BOTTOM 64 64 NO_FILL 1 false 0 0 0 0 0 false false 42 _("$"* #,##0_);_("$"* (#,##0);_("$"* "-"_);_(@_) 20 true false GENERAL NONE NONE NONE NONE 0 BOTTOM 64 64 NO_FILL 1 false 0 0 0 0 0 false false 9 0% xssf,默认字体个数:1 index color italic fontName underline bold strikeout typeOffset 0 8 false Calibri 0 false false 0 xssf,默认样式个数:1 1 2— — 3— — 4— — 5— — 6— — 7— — 8— — 9 10— — 11 12 13— — 14 15— — 16 17 18 19 20 21— — 22— — 23 24 0 true false GENERAL NONE NONE NONE NONE 8 BOTTOM 64 64 NO_FILL 0 false 0 8 8 8 0 false false 0 General
截图
这篇关于java-POI的Excel默认字体和样式的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-22项目:远程温湿度检测系统
- 2024-12-21《鸿蒙HarmonyOS应用开发从入门到精通(第2版)》简介
- 2024-12-21后台管理系统开发教程:新手入门全指南
- 2024-12-21后台开发教程:新手入门及实战指南
- 2024-12-21后台综合解决方案教程:新手入门指南
- 2024-12-21接口模块封装教程:新手必备指南
- 2024-12-21请求动作封装教程:新手必看指南
- 2024-12-21RBAC的权限教程:从入门到实践
- 2024-12-21登录鉴权实战:新手入门教程
- 2024-12-21动态权限实战入门指南