Merge branch 'main' of http://10.10.14.176:3000/huanghai/YunNanDsBase
commit
a5e201d96f
Binary file not shown.
Binary file not shown.
@ -0,0 +1,63 @@
|
||||
package com.dsideal.base.Tools.FillData.ExcelKit;
|
||||
|
||||
import org.apache.poi.ss.usermodel.BorderStyle;
|
||||
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
||||
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
||||
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
||||
import org.apache.poi.xssf.usermodel.XSSFFont;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class ExcelKit {
|
||||
/**
|
||||
* 获取表头样式
|
||||
*
|
||||
* @param workbook 指定的工作簿
|
||||
* @return
|
||||
*/
|
||||
public static XSSFCellStyle getHeaderStyle(XSSFWorkbook workbook) {
|
||||
XSSFCellStyle headerStyle = workbook.createCellStyle();
|
||||
XSSFFont font = workbook.createFont();
|
||||
font.setBold(true); // 设置字体加粗
|
||||
headerStyle.setFont(font);
|
||||
// 设置边框样式
|
||||
headerStyle.setBorderTop(BorderStyle.THIN);
|
||||
headerStyle.setBorderBottom(BorderStyle.THIN);
|
||||
headerStyle.setBorderLeft(BorderStyle.THIN);
|
||||
headerStyle.setBorderRight(BorderStyle.THIN);
|
||||
// 设置水平和垂直居中
|
||||
headerStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||
headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
return headerStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据样式
|
||||
* @param workbook 指定的工作簿
|
||||
* @return
|
||||
*/
|
||||
public static XSSFCellStyle getDataStyle(XSSFWorkbook workbook) {
|
||||
XSSFCellStyle dataStyle = workbook.createCellStyle();
|
||||
dataStyle.setBorderTop(BorderStyle.THIN); // 上边框
|
||||
dataStyle.setBorderBottom(BorderStyle.THIN); // 下边框
|
||||
dataStyle.setBorderLeft(BorderStyle.THIN); // 左边框
|
||||
dataStyle.setBorderRight(BorderStyle.THIN); // 右边框
|
||||
// 设置水平和垂直居中
|
||||
dataStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||
dataStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
return dataStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除Excel文件
|
||||
* @param excelPath
|
||||
*/
|
||||
public static void delExcel(String excelPath){
|
||||
//如果目录文件存在,则删除
|
||||
File fi = new File(excelPath);
|
||||
if (fi.exists()) {
|
||||
fi.delete();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue