poi设置excel字体颜色

 时间:2026-02-13 03:11:54

1、第一步:新建一个javaweb项目。

打开myeclipse file --》new--》web project 

具体操作如下图所示:

poi设置excel字体颜色

poi设置excel字体颜色

poi设置excel字体颜色

poi设置excel字体颜色

2、第二步:编写导出代码。

1、在项目中引入poi的依赖包poi-3.17.jar。

2、编写导出的代码

public static void main(String[] args) throws Exception{

//1.创建Excel对象

        Workbook wb =new HSSFWorkbook();

        //2.创建表格的sheet页

        Sheet sheet = wb.createSheet();

        //3.创建行

        Row row = sheet.createRow(3);

        //4.1创建列

        Cell cell = row.createCell(3);

        //4.2设置列宽便于展示

        sheet.setColumnWidth(3, 10000);

        //5设置内容

        cell.setCellValue("有困难找度娘");

        //6.设置样式

        //6.1创建字体

        Font font = wb.createFont();

        font.setFontHeightInPoints((short) 36);

        font.setFontName("华文琥珀");

        font.setColor(Font.COLOR_RED);

        //6.2创建单元格格式CellStyle

        CellStyle cellStyle = wb.createCellStyle();

        cellStyle.setFont(font);

        //6.3字体作用单元格

        cell.setCellStyle(cellStyle);

        //7.写入到硬盘

        //7.1创建流

        FileOutputStream os = new FileOutputStream(new File("E:/file/export.xls"));

        //7.2将wb的内容写入字符流中

        wb.write(os);

        //7.3关流

        os.flush();

        os.close();

    }

poi设置excel字体颜色

poi设置excel字体颜色

poi设置excel字体颜色

poi设置excel字体颜色

3、第三步:测试功能。

在测试类中右键执行run命令。如下图所示:

poi设置excel字体颜色

poi设置excel字体颜色

poi设置excel字体颜色

4、补充:font.setColor(Font.COLOR_RED);

1、poi文档提供了几个变量设置字体颜色。

2、自定义数据可以设置更多的颜色,不过如下

font.setColor((short)5); 黄色

font.setColor((short)7); 粉色

poi设置excel字体颜色

poi设置excel字体颜色

poi设置excel字体颜色

  • windows server 2003怎么安装FTP
  • VC6 MFC程序点击关闭按钮怎么弹出确认对话框
  • eclipse怎样修改包(package)的显示样式、格式
  • vmware vsphere6.0之使用OVF部署虚拟机
  • sublime text如何保存为uft-8无bom编码格式文件
  • 热门搜索
    湖州旅游景点大全 旅游法解读 连平旅游景点大全 昆明附近旅游景点 上海免费旅游景点大全 新西兰打工旅游签证 北京旅游团购 山东青岛旅游攻略 马尔代夫旅游团报价 海南有哪些旅游景点