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();
}
}
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/my773962804/article/details/84879507
内容来源于网络,如有侵权,请联系作者删除!