excelStyle

package com.chinatopv.util;

import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;

public class ExcelStyle {

    //设置表头样式
    public  static HSSFCellStyle getHeadStyle(HSSFWorkbook workbook){
     HSSFCellStyle cellstyle = workbook.createCellStyle();// 设置表头样式  
        cellstyle.setAlignment(CellStyle.ALIGN_CENTER);// 设置居中  
        HSSFFont headerFont = workbook.createFont(); //创建字体样式  
        headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); // 字体加粗  
        headerFont.setFontName("Times New Roman");  //设置字体类型  
        headerFont.setFontHeightInPoints((short) 16);
        cellstyle.setFont(headerFont);
        return cellstyle;

    }

//设置标题  以及内容样式
    public static CellStyle getTitleStyle(HSSFWorkbook workbook){
        CellStyle style = workbook.createCellStyle();
        style.setFillForegroundColor(CellStyle.THIN_BACKWARD_DIAG);
        style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);// 垂直居中
        style.setAlignment(CellStyle.ALIGN_CENTER);

style.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
        style.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
        style.setBorderTop(CellStyle.BORDER_THIN);// 上边框
        style.setBorderRight(CellStyle.BORDER_THIN);// 右边框
        style.setWrapText(true);
        return style;
    }

//设置字体颜色为红色
    public static HSSFFont getFontColor(HSSFWorkbook workbook){
         HSSFFont font = workbook.createFont();
         font.setColor(HSSFColor.RED.index);
         return font;
    }

//调整列宽度
    public static void setWidth(HSSFSheet sheet,int column){
        sheet.autoSizeColumn((short)column);
    }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值