如何更改文本颜色和填充颜色 [英] How do I change the Text Color and the Fillcolor

查看:45
本文介绍了如何更改文本颜色和填充颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将标题字体颜色更改为白色并填充绿色?这些是我正在使用的类:

How do I change the header font color to white and the fill green? These are the classes that I am using:

import static org.apache.poi.ss.usermodel.CellStyle.*
import static org.apache.poi.ss.usermodel.IndexedColors.*
import org.apache.poi.hssf.usermodel.*
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.Row
import org.apache.poi.ss.usermodel.Sheet
import org.apache.poi.ss.usermodel.Workbook
import org.apache.poi.ss.usermodel.Font

我相信,这是必须插入的代码.

And this is the code where, I believe, it will have to be inserted into.

Font headerFont = wb.createFont();
headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD)
CellStyle headerStyle = wb.createCellStyle()
headerStyle.setFont(headerFont)

cellMOPID.setCellStyle(headerStyle)
cellType.setCellStyle(headerStyle)
cellStatus.setCellStyle(headerStyle)
cellState.setCellStyle(headerStyle)
cellStartDate.setCellStyle(headerStyle)
cellEndDate.setCellStyle(headerStyle)
cellDesc.setCellStyle(headerStyle)

推荐答案

     HSSFCellStyle cellStyle = workBook.createCellStyle();        
     HSSFFont font = wb.createFont();
     font.setFontName(XSSFFont.DEFAULT_FONT_NAME);
     font.setFontHeightInPoints((short)10);
     font.setColor(IndexedColors.BLUE.getIndex());
     cellStyle.setFont(font);
    //the version i am using is poi-3.8

这篇关于如何更改文本颜色和填充颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆