java操作Excel的poi的字体设置

Posted nidegui

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java操作Excel的poi的字体设置相关的知识,希望对你有一定的参考价值。

package com.java.poi;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;

import java.io.FileOutputStream;

/**
* 字体设置
* @author nidegui
* @create 2019-06-17 11:30
*/
public class Test7
public static void main(String[] args) throws Exception

Workbook wb=new HSSFWorkbook();
Sheet sheet = wb.createSheet("sheet页");
Row row=sheet.createRow(1);

//创建一个字体
Font font=wb.createFont();
font.setFontHeightInPoints((short) 24);
font.setFontName("Courier New ");
font.setItalic(true);
font.setStrikeout(true);

CellStyle style=wb.createCellStyle();
style.setFont(font);

Cell cell = row.createCell((short) 1);
cell.setCellValue("this is test of fonts");
cell.setCellStyle(style);

FileOutputStream is=new FileOutputStream("E:\\\\3.xls");
wb.write(is);
is.close();

技术图片

 

以上是关于java操作Excel的poi的字体设置的主要内容,如果未能解决你的问题,请参考以下文章

14java实现poi操作excel,包括读和写日期格式,并且设置字体样式

转载:poi设置excel表格边框,字体等

java POI excel 导出复合样式(一个单元格两个字体)

poi Java生成excel合并单元格后字体居中

POI-----POI操作Excel-4字体

java 关于poi读取excel颜色