|
@@ -7,6 +7,7 @@ import com.management.platform.service.CorpwxJobResultService;
|
|
import com.management.platform.service.WxCorpInfoService;
|
|
import com.management.platform.service.WxCorpInfoService;
|
|
import org.apache.poi.hssf.usermodel.*;
|
|
import org.apache.poi.hssf.usermodel.*;
|
|
import org.apache.poi.ss.usermodel.*;
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
|
+import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
|
import org.apache.poi.xssf.usermodel.*;
|
|
import org.apache.poi.xssf.usermodel.*;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
@@ -27,7 +28,7 @@ public class ExcelUtil {
|
|
|
|
|
|
public static String exportGeneralExcelByTitleAndList(String title, List<List<String>> list, String downloadPath) {
|
|
public static String exportGeneralExcelByTitleAndList(String title, List<List<String>> list, String downloadPath) {
|
|
String result="系统提示:Excel文件导出成功!";
|
|
String result="系统提示:Excel文件导出成功!";
|
|
- String fileName= title+".xls";
|
|
|
|
|
|
+ String fileName= title+".xlsx";
|
|
try {
|
|
try {
|
|
// response.reset();
|
|
// response.reset();
|
|
// response.setHeader("Content-disposition",
|
|
// response.setHeader("Content-disposition",
|
|
@@ -36,25 +37,26 @@ public class ExcelUtil {
|
|
// response.setContentType("APPLICATION/OCTET-STREAM;charset=UTF-8");//设置类型
|
|
// response.setContentType("APPLICATION/OCTET-STREAM;charset=UTF-8");//设置类型
|
|
// response.setHeader("Cache-Control","no-cache");//设置头
|
|
// response.setHeader("Cache-Control","no-cache");//设置头
|
|
// response.setDateHeader("Expires", 0);//设置日期头
|
|
// response.setDateHeader("Expires", 0);//设置日期头
|
|
- // 创建工作簿
|
|
|
|
- HSSFWorkbook workBook = new HSSFWorkbook();
|
|
|
|
|
|
+ // 创建工作簿, 换成XSSSF 来支持万以上的数据
|
|
|
|
+ SXSSFWorkbook workBook = new SXSSFWorkbook();
|
|
|
|
+// HSSFWorkbook workBook = new HSSFWorkbook();
|
|
// 创建工作类
|
|
// 创建工作类
|
|
- HSSFSheet sheet = workBook.createSheet();
|
|
|
|
|
|
+ Sheet sheet = workBook.createSheet();
|
|
//设置首行冻结
|
|
//设置首行冻结
|
|
sheet.createFreezePane(0, 1);
|
|
sheet.createFreezePane(0, 1);
|
|
sheet.setDefaultColumnWidth(16);
|
|
sheet.setDefaultColumnWidth(16);
|
|
//设置字体样式
|
|
//设置字体样式
|
|
- HSSFFont headFont = workBook.createFont();
|
|
|
|
|
|
+ Font headFont = workBook.createFont();
|
|
headFont.setBold(true);
|
|
headFont.setBold(true);
|
|
headFont.setFontHeightInPoints((short) 10);
|
|
headFont.setFontHeightInPoints((short) 10);
|
|
headFont.setFontName("黑体");
|
|
headFont.setFontName("黑体");
|
|
|
|
|
|
- HSSFFont titleFont = workBook.createFont();
|
|
|
|
|
|
+ Font titleFont = workBook.createFont();
|
|
titleFont.setBold(true);
|
|
titleFont.setBold(true);
|
|
titleFont.setFontHeightInPoints((short) 10);
|
|
titleFont.setFontHeightInPoints((short) 10);
|
|
titleFont.setFontName("黑体");
|
|
titleFont.setFontName("黑体");
|
|
|
|
|
|
- HSSFFont font = workBook.createFont();
|
|
|
|
|
|
+ Font font = workBook.createFont();
|
|
font.setFontHeightInPoints((short) 10);
|
|
font.setFontHeightInPoints((short) 10);
|
|
font.setFontName("宋体");
|
|
font.setFontName("宋体");
|
|
|
|
|
|
@@ -76,9 +78,9 @@ public class ExcelUtil {
|
|
int b = Integer.parseInt((color.substring(4,6)),16);
|
|
int b = Integer.parseInt((color.substring(4,6)),16);
|
|
|
|
|
|
//自定义cell颜色
|
|
//自定义cell颜色
|
|
- HSSFPalette palette = workBook.getCustomPalette();
|
|
|
|
|
|
+// HSSFPalette palette = workBook.getCustomPalette();
|
|
//这里的9是索引
|
|
//这里的9是索引
|
|
- palette.setColorAtIndex((short)9, (byte) r, (byte) g, (byte) b);
|
|
|
|
|
|
+// palette.setColorAtIndex((short)9, (byte) r, (byte) g, (byte) b);
|
|
|
|
|
|
CellStyle titleStyle = workBook.createCellStyle();
|
|
CellStyle titleStyle = workBook.createCellStyle();
|
|
titleStyle.setFont(titleFont);
|
|
titleStyle.setFont(titleFont);
|
|
@@ -122,11 +124,11 @@ public class ExcelUtil {
|
|
*/
|
|
*/
|
|
int start = 0;
|
|
int start = 0;
|
|
for(List<String> rowList : list) {
|
|
for(List<String> rowList : list) {
|
|
- HSSFRow row = sheet.createRow(start);
|
|
|
|
|
|
+ Row row = sheet.createRow(start);
|
|
row.setHeightInPoints(24);
|
|
row.setHeightInPoints(24);
|
|
|
|
|
|
for(int i = 0; i < rowList.size(); i++) {
|
|
for(int i = 0; i < rowList.size(); i++) {
|
|
- HSSFCell cell = row.createCell(i);
|
|
|
|
|
|
+ Cell cell = row.createCell(i);
|
|
if(start == 0) {
|
|
if(start == 0) {
|
|
cell.setCellStyle(titleStyle);
|
|
cell.setCellStyle(titleStyle);
|
|
}else {
|
|
}else {
|
|
@@ -173,29 +175,30 @@ public class ExcelUtil {
|
|
// response.setHeader("Cache-Control","no-cache");//设置头
|
|
// response.setHeader("Cache-Control","no-cache");//设置头
|
|
// response.setDateHeader("Expires", 0);//设置日期头
|
|
// response.setDateHeader("Expires", 0);//设置日期头
|
|
// 创建工作簿
|
|
// 创建工作簿
|
|
- XSSFWorkbook workBook = new XSSFWorkbook();
|
|
|
|
|
|
+ SXSSFWorkbook workBook = new SXSSFWorkbook();
|
|
|
|
+// XSSFWorkbook workBook = new XSSFWorkbook();
|
|
// 创建工作类
|
|
// 创建工作类
|
|
- XSSFSheet sheet = workBook.createSheet();
|
|
|
|
|
|
+ Sheet sheet = workBook.createSheet();
|
|
//设置首行冻结
|
|
//设置首行冻结
|
|
sheet.createFreezePane(0, 1);
|
|
sheet.createFreezePane(0, 1);
|
|
sheet.setDefaultColumnWidth(16);
|
|
sheet.setDefaultColumnWidth(16);
|
|
//设置字体样式
|
|
//设置字体样式
|
|
- XSSFFont headFont = workBook.createFont();
|
|
|
|
|
|
+ Font headFont = workBook.createFont();
|
|
headFont.setBold(true);
|
|
headFont.setBold(true);
|
|
headFont.setFontHeightInPoints((short) 10);
|
|
headFont.setFontHeightInPoints((short) 10);
|
|
headFont.setFontName("黑体");
|
|
headFont.setFontName("黑体");
|
|
|
|
|
|
- XSSFFont titleFont = workBook.createFont();
|
|
|
|
|
|
+ Font titleFont = workBook.createFont();
|
|
titleFont.setBold(true);
|
|
titleFont.setBold(true);
|
|
titleFont.setFontHeightInPoints((short) 10);
|
|
titleFont.setFontHeightInPoints((short) 10);
|
|
titleFont.setFontName("黑体");
|
|
titleFont.setFontName("黑体");
|
|
|
|
|
|
- XSSFFont font = workBook.createFont();
|
|
|
|
|
|
+ Font font = workBook.createFont();
|
|
font.setFontHeightInPoints((short) 10);
|
|
font.setFontHeightInPoints((short) 10);
|
|
font.setFontName("宋体");
|
|
font.setFontName("宋体");
|
|
|
|
|
|
//设置单元格样式
|
|
//设置单元格样式
|
|
- XSSFCellStyle headStyle = workBook.createCellStyle();
|
|
|
|
|
|
+ CellStyle headStyle = workBook.createCellStyle();
|
|
headStyle.setFont(headFont);
|
|
headStyle.setFont(headFont);
|
|
headStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
headStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
headStyle.setVerticalAlignment(org.apache.poi.ss.usermodel.VerticalAlignment.CENTER);
|
|
headStyle.setVerticalAlignment(org.apache.poi.ss.usermodel.VerticalAlignment.CENTER);
|
|
@@ -206,7 +209,7 @@ public class ExcelUtil {
|
|
headStyle.setBorderRight(BorderStyle.THIN);//右边框
|
|
headStyle.setBorderRight(BorderStyle.THIN);//右边框
|
|
|
|
|
|
|
|
|
|
- XSSFCellStyle titleStyle = workBook.createCellStyle();
|
|
|
|
|
|
+ CellStyle titleStyle = workBook.createCellStyle();
|
|
titleStyle.setFont(titleFont);
|
|
titleStyle.setFont(titleFont);
|
|
titleStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
titleStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
titleStyle.setVerticalAlignment(org.apache.poi.ss.usermodel.VerticalAlignment.CENTER);
|
|
titleStyle.setVerticalAlignment(org.apache.poi.ss.usermodel.VerticalAlignment.CENTER);
|
|
@@ -218,7 +221,7 @@ public class ExcelUtil {
|
|
titleStyle.setBorderTop(BorderStyle.THIN);//上边框
|
|
titleStyle.setBorderTop(BorderStyle.THIN);//上边框
|
|
titleStyle.setBorderRight(BorderStyle.THIN);//右边框
|
|
titleStyle.setBorderRight(BorderStyle.THIN);//右边框
|
|
|
|
|
|
- XSSFCellStyle cellStyle = workBook.createCellStyle();
|
|
|
|
|
|
+ CellStyle cellStyle = workBook.createCellStyle();
|
|
cellStyle.setFont(font);
|
|
cellStyle.setFont(font);
|
|
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
cellStyle.setVerticalAlignment(org.apache.poi.ss.usermodel.VerticalAlignment.CENTER);
|
|
cellStyle.setVerticalAlignment(org.apache.poi.ss.usermodel.VerticalAlignment.CENTER);
|
|
@@ -248,11 +251,11 @@ public class ExcelUtil {
|
|
*/
|
|
*/
|
|
int start = 0;
|
|
int start = 0;
|
|
for(List<String> rowList : list) {
|
|
for(List<String> rowList : list) {
|
|
- XSSFRow row = sheet.createRow(start);
|
|
|
|
|
|
+ Row row = sheet.createRow(start);
|
|
row.setHeightInPoints(24);
|
|
row.setHeightInPoints(24);
|
|
|
|
|
|
for(int i = 0; i < rowList.size(); i++) {
|
|
for(int i = 0; i < rowList.size(); i++) {
|
|
- XSSFCell cell = row.createCell(i);
|
|
|
|
|
|
+ Cell cell = row.createCell(i);
|
|
if(start == 0) {
|
|
if(start == 0) {
|
|
cell.setCellStyle(titleStyle);
|
|
cell.setCellStyle(titleStyle);
|
|
}else {
|
|
}else {
|
|
@@ -289,29 +292,29 @@ public class ExcelUtil {
|
|
|
|
|
|
public static String exportTwoSheetGeneralExcelByTitleAndList(String title, List<List<String>> sheetOneList,List<List<String>> sheetTwoList, String downloadPath,String sheetOneName,String sheetTwoName) {
|
|
public static String exportTwoSheetGeneralExcelByTitleAndList(String title, List<List<String>> sheetOneList,List<List<String>> sheetTwoList, String downloadPath,String sheetOneName,String sheetTwoName) {
|
|
String result="系统提示:Excel文件导出成功!";
|
|
String result="系统提示:Excel文件导出成功!";
|
|
- String fileName= title+".xls";
|
|
|
|
|
|
+ String fileName= title+".xlsx";
|
|
try {
|
|
try {
|
|
// 创建工作簿
|
|
// 创建工作簿
|
|
- HSSFWorkbook workBook = new HSSFWorkbook();
|
|
|
|
|
|
+ SXSSFWorkbook workBook = new SXSSFWorkbook();
|
|
// 创建工作类
|
|
// 创建工作类
|
|
- HSSFSheet sheetOne = workBook.createSheet();
|
|
|
|
|
|
+ Sheet sheetOne = workBook.createSheet();
|
|
workBook.setSheetName(0,sheetOneName);
|
|
workBook.setSheetName(0,sheetOneName);
|
|
- HSSFSheet sheetTwo = workBook.createSheet();
|
|
|
|
|
|
+ Sheet sheetTwo = workBook.createSheet();
|
|
workBook.setSheetName(1,sheetTwoName);
|
|
workBook.setSheetName(1,sheetTwoName);
|
|
sheetOne.setDefaultColumnWidth(16);
|
|
sheetOne.setDefaultColumnWidth(16);
|
|
sheetTwo.setDefaultColumnWidth(16);
|
|
sheetTwo.setDefaultColumnWidth(16);
|
|
//设置字体样式
|
|
//设置字体样式
|
|
- HSSFFont headFont = workBook.createFont();
|
|
|
|
|
|
+ Font headFont = workBook.createFont();
|
|
headFont.setBold(true);
|
|
headFont.setBold(true);
|
|
headFont.setFontHeightInPoints((short) 10);
|
|
headFont.setFontHeightInPoints((short) 10);
|
|
headFont.setFontName("黑体");
|
|
headFont.setFontName("黑体");
|
|
|
|
|
|
- HSSFFont titleFont = workBook.createFont();
|
|
|
|
|
|
+ Font titleFont = workBook.createFont();
|
|
titleFont.setBold(true);
|
|
titleFont.setBold(true);
|
|
titleFont.setFontHeightInPoints((short) 10);
|
|
titleFont.setFontHeightInPoints((short) 10);
|
|
titleFont.setFontName("黑体");
|
|
titleFont.setFontName("黑体");
|
|
|
|
|
|
- HSSFFont font = workBook.createFont();
|
|
|
|
|
|
+ Font font = workBook.createFont();
|
|
font.setFontHeightInPoints((short) 10);
|
|
font.setFontHeightInPoints((short) 10);
|
|
font.setFontName("宋体");
|
|
font.setFontName("宋体");
|
|
|
|
|
|
@@ -333,9 +336,9 @@ public class ExcelUtil {
|
|
int b = Integer.parseInt((color.substring(4,6)),16);
|
|
int b = Integer.parseInt((color.substring(4,6)),16);
|
|
|
|
|
|
//自定义cell颜色
|
|
//自定义cell颜色
|
|
- HSSFPalette palette = workBook.getCustomPalette();
|
|
|
|
|
|
+// HSSFPalette palette = workBook.getCustomPalette();
|
|
//这里的9是索引
|
|
//这里的9是索引
|
|
- palette.setColorAtIndex((short)9, (byte) r, (byte) g, (byte) b);
|
|
|
|
|
|
+// palette.setColorAtIndex((short)9, (byte) r, (byte) g, (byte) b);
|
|
|
|
|
|
CellStyle titleStyle = workBook.createCellStyle();
|
|
CellStyle titleStyle = workBook.createCellStyle();
|
|
titleStyle.setFont(titleFont);
|
|
titleStyle.setFont(titleFont);
|
|
@@ -379,10 +382,10 @@ public class ExcelUtil {
|
|
*/
|
|
*/
|
|
int start = 0;
|
|
int start = 0;
|
|
for(List<String> rowList : sheetOneList) {
|
|
for(List<String> rowList : sheetOneList) {
|
|
- HSSFRow row = sheetOne.createRow(start);
|
|
|
|
|
|
+ Row row = sheetOne.createRow(start);
|
|
row.setHeightInPoints(24);
|
|
row.setHeightInPoints(24);
|
|
for(int i = 0; i < rowList.size(); i++) {
|
|
for(int i = 0; i < rowList.size(); i++) {
|
|
- HSSFCell cell = row.createCell(i);
|
|
|
|
|
|
+ Cell cell = row.createCell(i);
|
|
if(start == 0) {
|
|
if(start == 0) {
|
|
cell.setCellStyle(titleStyle);
|
|
cell.setCellStyle(titleStyle);
|
|
}else {
|
|
}else {
|
|
@@ -396,10 +399,10 @@ public class ExcelUtil {
|
|
if(sheetTwoList.size()>0){
|
|
if(sheetTwoList.size()>0){
|
|
int start = 0;
|
|
int start = 0;
|
|
for(List<String> rowList : sheetTwoList) {
|
|
for(List<String> rowList : sheetTwoList) {
|
|
- HSSFRow row = sheetTwo.createRow(start);
|
|
|
|
|
|
+ Row row = sheetTwo.createRow(start);
|
|
row.setHeightInPoints(24);
|
|
row.setHeightInPoints(24);
|
|
for(int i = 0; i < rowList.size(); i++) {
|
|
for(int i = 0; i < rowList.size(); i++) {
|
|
- HSSFCell cell = row.createCell(i);
|
|
|
|
|
|
+ Cell cell = row.createCell(i);
|
|
if(start == 0) {
|
|
if(start == 0) {
|
|
cell.setCellStyle(titleStyle);
|
|
cell.setCellStyle(titleStyle);
|
|
}else {
|
|
}else {
|
|
@@ -428,28 +431,28 @@ public class ExcelUtil {
|
|
|
|
|
|
public static String exportMultiSheetGeneralExcelByTitleAndList(String title, List<List<String>>[] multiSheetList, String downloadPath,String[] sheetsName) {
|
|
public static String exportMultiSheetGeneralExcelByTitleAndList(String title, List<List<String>>[] multiSheetList, String downloadPath,String[] sheetsName) {
|
|
String result="系统提示:Excel文件导出成功!";
|
|
String result="系统提示:Excel文件导出成功!";
|
|
- String fileName= title+".xls";
|
|
|
|
|
|
+ String fileName= title+".xlsx";
|
|
try {
|
|
try {
|
|
// 创建工作簿
|
|
// 创建工作簿
|
|
- HSSFWorkbook workBook = new HSSFWorkbook();
|
|
|
|
|
|
+ SXSSFWorkbook workBook = new SXSSFWorkbook();
|
|
// 创建工作类
|
|
// 创建工作类
|
|
for (int sheetIndex=0;sheetIndex<multiSheetList.length; sheetIndex++) {
|
|
for (int sheetIndex=0;sheetIndex<multiSheetList.length; sheetIndex++) {
|
|
- HSSFSheet sheetOne = workBook.createSheet();
|
|
|
|
|
|
+ Sheet sheetOne = workBook.createSheet();
|
|
workBook.setSheetName(sheetIndex,sheetsName[sheetIndex]);
|
|
workBook.setSheetName(sheetIndex,sheetsName[sheetIndex]);
|
|
sheetOne.setDefaultColumnWidth(16);
|
|
sheetOne.setDefaultColumnWidth(16);
|
|
|
|
|
|
//设置字体样式
|
|
//设置字体样式
|
|
- HSSFFont headFont = workBook.createFont();
|
|
|
|
|
|
+ Font headFont = workBook.createFont();
|
|
headFont.setBold(true);
|
|
headFont.setBold(true);
|
|
headFont.setFontHeightInPoints((short) 10);
|
|
headFont.setFontHeightInPoints((short) 10);
|
|
headFont.setFontName("黑体");
|
|
headFont.setFontName("黑体");
|
|
|
|
|
|
- HSSFFont titleFont = workBook.createFont();
|
|
|
|
|
|
+ Font titleFont = workBook.createFont();
|
|
titleFont.setBold(true);
|
|
titleFont.setBold(true);
|
|
titleFont.setFontHeightInPoints((short) 10);
|
|
titleFont.setFontHeightInPoints((short) 10);
|
|
titleFont.setFontName("黑体");
|
|
titleFont.setFontName("黑体");
|
|
|
|
|
|
- HSSFFont font = workBook.createFont();
|
|
|
|
|
|
+ Font font = workBook.createFont();
|
|
font.setFontHeightInPoints((short) 10);
|
|
font.setFontHeightInPoints((short) 10);
|
|
font.setFontName("宋体");
|
|
font.setFontName("宋体");
|
|
|
|
|
|
@@ -471,9 +474,9 @@ public class ExcelUtil {
|
|
int b = Integer.parseInt((color.substring(4,6)),16);
|
|
int b = Integer.parseInt((color.substring(4,6)),16);
|
|
|
|
|
|
//自定义cell颜色
|
|
//自定义cell颜色
|
|
- HSSFPalette palette = workBook.getCustomPalette();
|
|
|
|
|
|
+// HSSFPalette palette = workBook.getCustomPalette();
|
|
//这里的9是索引
|
|
//这里的9是索引
|
|
- palette.setColorAtIndex((short)9, (byte) r, (byte) g, (byte) b);
|
|
|
|
|
|
+// palette.setColorAtIndex((short)9, (byte) r, (byte) g, (byte) b);
|
|
|
|
|
|
CellStyle titleStyle = workBook.createCellStyle();
|
|
CellStyle titleStyle = workBook.createCellStyle();
|
|
titleStyle.setFont(titleFont);
|
|
titleStyle.setFont(titleFont);
|
|
@@ -500,10 +503,10 @@ public class ExcelUtil {
|
|
if(multiSheetList[sheetIndex].size() > 0) {
|
|
if(multiSheetList[sheetIndex].size() > 0) {
|
|
int start = 0;
|
|
int start = 0;
|
|
for(List<String> rowList : multiSheetList[sheetIndex]) {
|
|
for(List<String> rowList : multiSheetList[sheetIndex]) {
|
|
- HSSFRow row = sheetOne.createRow(start);
|
|
|
|
|
|
+ Row row = sheetOne.createRow(start);
|
|
row.setHeightInPoints(24);
|
|
row.setHeightInPoints(24);
|
|
for(int i = 0; i < rowList.size(); i++) {
|
|
for(int i = 0; i < rowList.size(); i++) {
|
|
- HSSFCell cell = row.createCell(i);
|
|
|
|
|
|
+ Cell cell = row.createCell(i);
|
|
if(start == 0) {
|
|
if(start == 0) {
|
|
cell.setCellStyle(titleStyle);
|
|
cell.setCellStyle(titleStyle);
|
|
}else {
|
|
}else {
|