ExcelExportUtil自定义样式

ExcelExportUtil工具类提供的样式不是很能满足业务需求,可以更改它的ExcelExportStylerDefaultImpl类,或者重写这个类,再使用

原类:

* Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com)
package org.jeecgframework.poi.excel.export.styler;

import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Workbook;

/**
* 鏍峰紡鐨勯粯璁ゅ疄鐜�
* @author JueYue
* 2015骞�1鏈�9鏃� 涓嬪崍5:36:08
*/
public class ExcelExportStylerDefaultImpl extends AbstractExcelExportStyler
implements IExcelExportStyler {

public ExcelExportStylerDefaultImpl(Workbook workbook) {
super.createStyles(workbook);
}

@Override
public CellStyle getTitleStyle(short color) {
CellStyle titleStyle = workbook.createCellStyle();
titleStyle.setAlignment(CellStyle.ALIGN_CENTER);
titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
titleStyle.setWrapText(true);
return titleStyle;
}

@Override
public CellStyle stringSeptailStyle(Workbook workbook, boolean isWarp) {
CellStyle style = workbook.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setDataFormat(STRING_FORMAT);
if (isWarp) {
style.setWrapText(true);
}
return style;
}

@Override
public CellStyle getHeaderStyle(short color) {
CellStyle titleStyle = workbook.createCellStyle();
Font font = workbook.createFont();
font.setFontHeightInPoints((short) 12);
titleStyle.setFont(font);
titleStyle.setAlignment(CellStyle.ALIGN_CENTER);
titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
return titleStyle;
}

@Override
public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) {
CellStyle style = workbook.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setDataFormat(STRING_FORMAT);
if (isWarp) {
style.setWrapText(true);
}
return style;
}

}

 

重写的类:

package com.longruan.hnny.util;

import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Workbook;
import org.jeecgframework.poi.excel.export.styler.AbstractExcelExportStyler;
import org.jeecgframework.poi.excel.export.styler.IExcelExportStyler;

/**
* 2 * @author LiaoYunChuan
*/
public class ExcelExportStylerUtil extends AbstractExcelExportStyler implements IExcelExportStyler {

public ExcelExportStylerUtil(Workbook workbook) {
super.createStyles(workbook);
}

@Override
public CellStyle getTitleStyle(short color) {
CellStyle titleStyle = workbook.createCellStyle();
titleStyle.setAlignment(CellStyle.ALIGN_CENTER);
titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
titleStyle.setBorderBottom(CellStyle.BORDER_THIN); //下边框
titleStyle.setBorderLeft(CellStyle.BORDER_THIN);//左边框
titleStyle.setBorderTop(CellStyle.BORDER_THIN);//上边框
titleStyle.setBorderRight(CellStyle.BORDER_THIN);//右边框
titleStyle.setWrapText(true);
return titleStyle;
}

@Override
public CellStyle stringSeptailStyle(Workbook workbook, boolean isWarp) {
CellStyle style = workbook.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setBorderBottom(CellStyle.BORDER_THIN); //下边框
style.setBorderLeft(CellStyle.BORDER_THIN);//左边框
style.setBorderTop(CellStyle.BORDER_THIN);//上边框
style.setBorderRight(CellStyle.BORDER_THIN);//右边框
style.setDataFormat(STRING_FORMAT);
if (isWarp) {
style.setWrapText(true);
}
return style;
}

@Override
public CellStyle getHeaderStyle(short color) {
CellStyle titleStyle = workbook.createCellStyle();
Font font = workbook.createFont();
font.setFontHeightInPoints((short) 12);
titleStyle.setFont(font);
titleStyle.setAlignment(CellStyle.ALIGN_CENTER);
titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
titleStyle.setBorderBottom(CellStyle.BORDER_THIN); //下边框
titleStyle.setBorderLeft(CellStyle.BORDER_THIN);//左边框
titleStyle.setBorderTop(CellStyle.BORDER_THIN);//上边框
titleStyle.setBorderRight(CellStyle.BORDER_THIN);//右边框
return titleStyle;
}

@Override
public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) {
CellStyle style = workbook.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setBorderBottom(CellStyle.BORDER_THIN); //下边框
style.setBorderLeft(CellStyle.BORDER_THIN);//左边框
style.setBorderTop(CellStyle.BORDER_THIN);//上边框
style.setBorderRight(CellStyle.BORDER_THIN);//右边框
style.setDataFormat(STRING_FORMAT);
if (isWarp) {
style.setWrapText(true);
}
return style;
}

}

只是设置了边框,其他操作也是一样

使用:

ExcelExportUtil自定义样式

 

上一篇:php-强烈处理Apache字符


下一篇:PHP-Codeigniter中的自动完成