【poi第七节】poi设置excel 设置字体格式,java设置excel设置字体格式

poi设置excel 设置字体格式,java设置excel设置字体格式

import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

/**
 * @ClassName 类名:ExcelDemo7
 * @Author作者: hzh
 * @Date时间:2018/12/4 15:13
 * 设置字体格式
 **/
public class ExcelDemo7 {

    public static void main(String[] args) throws Exception {
        Workbook wb = new HSSFWorkbook();
        Sheet sheet = wb.createSheet("hi sheet");
        Row row = sheet.createRow(1);
        Font font = wb.createFont();
        font.setBold(true);
        font.setColor((short) 13);
        font.setFontHeightInPoints((short) 24);
        font.setFontName("宋体");
        CellStyle cellStyle = wb.createCellStyle();
        cellStyle.setFont(font);
        Cell cell = row.createCell(1);
        cell.setCellValue("这是测试字体格式的");
        cell.setCellStyle(cellStyle);
        FileOutputStream fileOutputStream = new FileOutputStream("D://file//font.xls");
        wb.write(fileOutputStream);
        wb.close();
    }
}

 

你可能感兴趣的:(POI,excel,poi设置字体格式,java设置excel字体格式)