poi HSSFRichTextString 对cell中的每一段文字设置字体

时间:2023-03-09 03:09:23
poi HSSFRichTextString 对cell中的每一段文字设置字体

HSSFRichTextString ts= new HSSFRichTextString(" 经审核,我司已同意其出库申请。请你部按规定将托管银行承兑汇票办理出库。" +
"我公司指派___________________(身份证号:_____________________________________)" +
"、___________________(身份证号:_____________________________________)" +
"和___________________(身份证号:_____________________________________)" +
"持本通知书办理提票事项,并请你部将出库票据移交_________________和_________________两人签收。");
________ 在宋体格式下显示为_ _ ,所以将"___"字体设置为Arial,将文字字体设置为宋体
HSSFFont font = xls.createFont();
font.setFontHeightInPoints((short)10); // 设置字体大小
font.setFontName("宋体");
ts.applyFont(0, 45, font);
ts.applyFont(64, 70, font);
ts.applyFont(107, 109, font);
ts.applyFont(128, 134, font);
ts.applyFont(171, 173, font);
ts.applyFont(193, 198, font);
ts.applyFont(235, 258, font);
ts.applyFont(275, 275, font);
ts.applyFont(294, 299, font);
HSSFFont font1 = xls.createFont();
font1.setFontHeightInPoints((short)10); // 设置字体大小
font1.setFontName("Arial");
ts.applyFont(45, 64, font1);
ts.applyFont(70, 107, font1);
ts.applyFont(109, 128, font1);
ts.applyFont(134, 171, font1);
ts.applyFont(173, 192, font1);
ts.applyFont(198, 235, font1);
ts.applyFont(258, 275, font1);
ts.applyFont(276, 294, font1);
cell.setCellValue(ts);