ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

java-POI的Excel默认字体和样式

2022-03-21 17:05:36  阅读:310  来源: 互联网

标签:NONE false Excel System 64 POI print java out


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

截图

在这里插入图片描述
在这里插入图片描述

标签:NONE,false,Excel,System,64,POI,print,java,out
来源: https://blog.csdn.net/privateobject/article/details/123639946

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有