java版poi内置的Font和CellStyle,本来以为是没有的,通过代码测试 发现有还不一样。
<poi.varsion>3.17poi.varsion>
<dependency>
<groupId>org.apache.poigroupId>
<artifactId>poiartifactId>
<version>${poi.varsion}version>
dependency>
<dependency>
<groupId>org.apache.poigroupId>
<artifactId>poi-ooxmlartifactId>
<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