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

x33g5p2x  于2021-12-28 转载在 其他  
字(1.1k)|赞(0)|评价(0)|浏览(612)

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();
    }
}

相关文章