forked from github/easyexcel
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.8 KiB
87 lines
2.8 KiB
package com.alibaba.excel.util; |
|
|
|
import org.apache.poi.ss.usermodel.BorderStyle; |
|
import org.apache.poi.ss.usermodel.CellStyle; |
|
import org.apache.poi.ss.usermodel.FillPatternType; |
|
import org.apache.poi.ss.usermodel.Font; |
|
import org.apache.poi.ss.usermodel.HorizontalAlignment; |
|
import org.apache.poi.ss.usermodel.IndexedColors; |
|
import org.apache.poi.ss.usermodel.VerticalAlignment; |
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
|
/** |
|
* @author jipengfei |
|
*/ |
|
public class StyleUtil { |
|
|
|
/** |
|
* |
|
* @param workbook |
|
* @return |
|
*/ |
|
public static CellStyle buildDefaultCellStyle(Workbook workbook) { |
|
CellStyle newCellStyle = workbook.createCellStyle(); |
|
Font font = workbook.createFont(); |
|
font.setFontName("宋体"); |
|
font.setFontHeightInPoints((short)14); |
|
font.setBold(true); |
|
newCellStyle.setFont(font); |
|
newCellStyle.setWrapText(true); |
|
newCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); |
|
newCellStyle.setAlignment(HorizontalAlignment.CENTER); |
|
newCellStyle.setLocked(true); |
|
newCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); |
|
newCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); |
|
newCellStyle.setBorderBottom(BorderStyle.THIN); |
|
newCellStyle.setBorderLeft(BorderStyle.THIN); |
|
return newCellStyle; |
|
} |
|
|
|
/** |
|
* |
|
* @param workbook |
|
* @param f |
|
* @param indexedColors |
|
* @return |
|
*/ |
|
public static CellStyle buildHeadCellStyle(Workbook workbook, com.alibaba.excel.metadata.Font f, |
|
IndexedColors indexedColors) { |
|
CellStyle cellStyle = workbook.createCellStyle(); |
|
return buildCellStyle(workbook, cellStyle, f, indexedColors); |
|
} |
|
|
|
/** |
|
* |
|
* @param workbook |
|
* @param f |
|
* @param indexedColors |
|
* @return |
|
*/ |
|
public static CellStyle buildContentCellStyle(Workbook workbook, com.alibaba.excel.metadata.Font f, |
|
IndexedColors indexedColors) { |
|
CellStyle cellStyle = buildDefaultCellStyle(workbook); |
|
return buildCellStyle(workbook, cellStyle, f, indexedColors); |
|
} |
|
|
|
/** |
|
* |
|
* @param workbook |
|
* @param f |
|
* @param indexedColors |
|
* @return |
|
*/ |
|
private static CellStyle buildCellStyle(Workbook workbook, CellStyle cellStyle, com.alibaba.excel.metadata.Font f, |
|
IndexedColors indexedColors) { |
|
if (f != null) { |
|
Font font = workbook.createFont(); |
|
font.setFontName(f.getFontName()); |
|
font.setFontHeightInPoints(f.getFontHeightInPoints()); |
|
font.setBold(f.isBold()); |
|
cellStyle.setFont(font); |
|
} |
|
if (indexedColors != null) { |
|
cellStyle.setFillForegroundColor(indexedColors.getIndex()); |
|
} |
|
return cellStyle; |
|
} |
|
}
|
|
|