|
@@ -8,23 +8,19 @@ import com.ywt.mg.domain.models.ExcelStyleMap;
|
|
import com.ywt.mg.domain.models.pojo.CustomExcelItem;
|
|
import com.ywt.mg.domain.models.pojo.CustomExcelItem;
|
|
import com.ywt.mg.domain.models.pojo.ExcelCollectPojo;
|
|
import com.ywt.mg.domain.models.pojo.ExcelCollectPojo;
|
|
import jxl.Workbook;
|
|
import jxl.Workbook;
|
|
-import jxl.format.*;
|
|
|
|
import jxl.format.Alignment;
|
|
import jxl.format.Alignment;
|
|
import jxl.format.Border;
|
|
import jxl.format.Border;
|
|
import jxl.format.BorderLineStyle;
|
|
import jxl.format.BorderLineStyle;
|
|
import jxl.format.Colour;
|
|
import jxl.format.Colour;
|
|
import jxl.format.VerticalAlignment;
|
|
import jxl.format.VerticalAlignment;
|
|
|
|
+import jxl.format.*;
|
|
import jxl.write.*;
|
|
import jxl.write.*;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
-import org.springframework.web.context.request.RequestContextHolder;
|
|
|
|
-import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.ByteArrayOutputStream;
|
|
-import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.OutputStream;
|
|
import java.io.OutputStream;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
@@ -288,7 +284,7 @@ public class ExcelDownloadSrv {
|
|
* @author Walker, added on 06/27/2019.
|
|
* @author Walker, added on 06/27/2019.
|
|
*/
|
|
*/
|
|
public OutputStream generateAndReturnExcelFileWithNoStyleAndCollectLocal(String fileName, String path, ExcelDataMap data, ExcelStyleMap excelStyleMap,
|
|
public OutputStream generateAndReturnExcelFileWithNoStyleAndCollectLocal(String fileName, String path, ExcelDataMap data, ExcelStyleMap excelStyleMap,
|
|
- List<ExcelCollectPojo> collectList) throws AppMessageException {
|
|
|
|
|
|
+ List<ExcelCollectPojo> collectList, int size) throws AppMessageException {
|
|
|
|
|
|
OutputStream ba = null;
|
|
OutputStream ba = null;
|
|
ba = new ByteArrayOutputStream();
|
|
ba = new ByteArrayOutputStream();
|
|
@@ -301,72 +297,180 @@ public class ExcelDownloadSrv {
|
|
// 创建写工作簿对象
|
|
// 创建写工作簿对象
|
|
// WritableWorkbook workbook = Workbook.createWorkbook(file);
|
|
// WritableWorkbook workbook = Workbook.createWorkbook(file);
|
|
workbook = Workbook.createWorkbook(ba);
|
|
workbook = Workbook.createWorkbook(ba);
|
|
- // 工作表
|
|
|
|
- WritableSheet sheet = workbook.createSheet(fileName, 0);
|
|
|
|
|
|
|
|
- //表头格式
|
|
|
|
- WritableCellFormat cellFormat = ExcelDownloadSrv.getWritableCellFormat();
|
|
|
|
- //数据行格式
|
|
|
|
- // 设置背景、字体颜色、对齐方式等等;
|
|
|
|
- WritableFont font2 = new WritableFont(WritableFont.ARIAL, 14, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
|
|
|
|
- WritableCellFormat cellFormat2 = new WritableCellFormat(font2);
|
|
|
|
- //设置文字居中对齐方式;
|
|
|
|
- cellFormat2.setAlignment(Alignment.CENTRE);
|
|
|
|
- //设置垂直居中;
|
|
|
|
- cellFormat2.setVerticalAlignment(VerticalAlignment.CENTRE);
|
|
|
|
- cellFormat2.setBackground(Colour.WHITE);
|
|
|
|
- cellFormat2.setBorder(Border.ALL, BorderLineStyle.THIN);
|
|
|
|
- cellFormat2.setWrap(true);
|
|
|
|
- //给sheet电子版中所有的列设置默认的列的宽度;
|
|
|
|
- sheet.getSettings().setDefaultColumnWidth(20);
|
|
|
|
- sheet.getSettings().setDefaultRowHeight(30 * 20);
|
|
|
|
|
|
+ int list = size;
|
|
|
|
+ int a = 0;
|
|
|
|
+ if(list < 60000){
|
|
|
|
+ a = 1;
|
|
|
|
+ } else {
|
|
|
|
+ if (list % 60000 == 0) {
|
|
|
|
+ a = list / 60000;
|
|
|
|
+ } else {
|
|
|
|
+ a = list / 60000 + 1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- //单独应用样式
|
|
|
|
- if (excelStyleMap != null) {
|
|
|
|
- for (String column : excelStyleMap.keySet()) {
|
|
|
|
- // 指定列宽
|
|
|
|
- int styleColumnWidth = excelStyleMap.getIntValueSafely(column, ExcelStyleMap.STYLE_COLUMN_WIDTH, 0);
|
|
|
|
- List<String> columns = new ArrayList<>(data.keySet());
|
|
|
|
- for (int i = 0; i < columns.size(); i++) {
|
|
|
|
- if (columns.get(i).equals(column)) {
|
|
|
|
- sheet.setColumnView(i, styleColumnWidth);
|
|
|
|
|
|
+ // 工作表
|
|
|
|
+ for (int i = 0; i < a; i++) {
|
|
|
|
+ int page = i + 1;
|
|
|
|
+ WritableSheet sheet = workbook.createSheet(fileName + page, 0);
|
|
|
|
+ WritableCellFormat cellFormat = ExcelDownloadSrv.getWritableCellFormat();
|
|
|
|
+ //数据行格式
|
|
|
|
+ // 设置背景、字体颜色、对齐方式等等;
|
|
|
|
+ WritableFont font2 = new WritableFont(WritableFont.ARIAL, 14, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
|
|
|
|
+ WritableCellFormat cellFormat2 = new WritableCellFormat(font2);
|
|
|
|
+ //设置文字居中对齐方式;
|
|
|
|
+ cellFormat2.setAlignment(Alignment.CENTRE);
|
|
|
|
+ //设置垂直居中;
|
|
|
|
+ cellFormat2.setVerticalAlignment(VerticalAlignment.CENTRE);
|
|
|
|
+ cellFormat2.setBackground(Colour.WHITE);
|
|
|
|
+ cellFormat2.setBorder(Border.ALL, BorderLineStyle.THIN);
|
|
|
|
+ cellFormat2.setWrap(true);
|
|
|
|
+ //给sheet电子版中所有的列设置默认的列的宽度;
|
|
|
|
+ sheet.getSettings().setDefaultColumnWidth(20);
|
|
|
|
+ sheet.getSettings().setDefaultRowHeight(30 * 20);
|
|
|
|
+ int firstRow = 0;
|
|
|
|
+ //填充表头
|
|
|
|
+ int headerColumn = 0;
|
|
|
|
+// int headerColumn2 = 0;
|
|
|
|
+// int headerColumn3 = 0;
|
|
|
|
+ for (String key : data.keySet()) {
|
|
|
|
+ Label label = new Label(headerColumn, firstRow, key, cellFormat);
|
|
|
|
+ sheet.addCell(label);
|
|
|
|
+// Label label2 = new Label(headerColumn2, firstRow, key, cellFormat);
|
|
|
|
+// sheet2.addCell(label2);
|
|
|
|
+// Label label3 = new Label(headerColumn3, firstRow, key, cellFormat);
|
|
|
|
+// sheet3.addCell(label3);
|
|
|
|
+ List<String> colData = data.get(key);
|
|
|
|
+ for (int q = 0; q < 60000; q++) {
|
|
|
|
+ int e = 60000 * i;
|
|
|
|
+ Label lb = new Label(headerColumn, q + 1, Checker.getStringValue(colData.get(e + q)), cellFormat);
|
|
|
|
+ sheet.addCell(lb);
|
|
|
|
+// sheet2.addCell(lb);
|
|
|
|
+ }
|
|
|
|
+// for (int q = 0; q < 2; q++) {
|
|
|
|
+// Label lb = new Label(headerColumn2, q + 1, Checker.getStringValue(colData.get(2 + q)), cellFormat);
|
|
|
|
+// sheet2.addCell(lb);
|
|
|
|
+// }
|
|
|
|
+// for (int q = 0; q < 2; q++) {
|
|
|
|
+// Label lb = new Label(headerColumn3, q + 1, Checker.getStringValue(colData.get(4 + q)), cellFormat);
|
|
|
|
+// sheet3.addCell(lb);
|
|
|
|
+// }
|
|
|
|
+ headerColumn++;
|
|
|
|
+// headerColumn2++;
|
|
|
|
+// headerColumn3++;
|
|
|
|
+ }
|
|
|
|
+ if (i == a - 1) {
|
|
|
|
+ if (!Checker.isNone(collectList)) {
|
|
|
|
+ for (ExcelCollectPojo pojo : collectList) {
|
|
|
|
+ String[] dataArr = pojo.getDataArr();
|
|
|
|
+ for (int r = 0, j = dataArr.length; r < j; r++) {
|
|
|
|
+// Label lb = new Label(pojo.getCol() + i, pojo.getRow(), dataArr[i], cellFormat);
|
|
|
|
+// sheet.addCell(lb);
|
|
|
|
+ Label lb2 = new Label(pojo.getCol() + r, pojo.getRow(), dataArr[r], cellFormat);
|
|
|
|
+ sheet.addCell(lb2);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+// WritableSheet sheet = workbook.createSheet(fileName, 0);
|
|
|
|
+// WritableSheet sheet2 = workbook.createSheet(fileName + "2", 1);
|
|
|
|
+// WritableSheet sheet3 = workbook.createSheet(fileName + "3", 2);
|
|
|
|
+//
|
|
|
|
+// //表头格式
|
|
|
|
+// WritableCellFormat cellFormat = ExcelDownloadSrv.getWritableCellFormat();
|
|
|
|
+// //数据行格式
|
|
|
|
+// // 设置背景、字体颜色、对齐方式等等;
|
|
|
|
+// WritableFont font2 = new WritableFont(WritableFont.ARIAL, 14, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
|
|
|
|
+// WritableCellFormat cellFormat2 = new WritableCellFormat(font2);
|
|
|
|
+// //设置文字居中对齐方式;
|
|
|
|
+// cellFormat2.setAlignment(Alignment.CENTRE);
|
|
|
|
+// //设置垂直居中;
|
|
|
|
+// cellFormat2.setVerticalAlignment(VerticalAlignment.CENTRE);
|
|
|
|
+// cellFormat2.setBackground(Colour.WHITE);
|
|
|
|
+// cellFormat2.setBorder(Border.ALL, BorderLineStyle.THIN);
|
|
|
|
+// cellFormat2.setWrap(true);
|
|
|
|
+// //给sheet电子版中所有的列设置默认的列的宽度;
|
|
|
|
+// sheet.getSettings().setDefaultColumnWidth(20);
|
|
|
|
+// sheet.getSettings().setDefaultRowHeight(30 * 20);
|
|
|
|
+// sheet2.getSettings().setDefaultColumnWidth(20);
|
|
|
|
+// sheet2.getSettings().setDefaultRowHeight(30 * 20);
|
|
|
|
+// sheet3.getSettings().setDefaultColumnWidth(20);
|
|
|
|
+// sheet3.getSettings().setDefaultRowHeight(30 * 20);
|
|
|
|
+
|
|
|
|
+// //单独应用样式
|
|
|
|
+// if (excelStyleMap != null) {
|
|
|
|
+// for (String column : excelStyleMap.keySet()) {
|
|
|
|
+// // 指定列宽
|
|
|
|
+// int styleColumnWidth = excelStyleMap.getIntValueSafely(column, ExcelStyleMap.STYLE_COLUMN_WIDTH, 0);
|
|
|
|
+// List<String> columns = new ArrayList<>(data.keySet());
|
|
|
|
+// for (int i = 0; i <1; i++) {
|
|
|
|
+// if (columns.get(i).equals(column)) {
|
|
|
|
+// sheet.setColumnView(i, styleColumnWidth);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
+// }
|
|
// // 设置格式(实线)
|
|
// // 设置格式(实线)
|
|
// WritableCellFormat cellFormat = new WritableCellFormat();
|
|
// WritableCellFormat cellFormat = new WritableCellFormat();
|
|
// //给sheet电子版中所有的列设置默认的列的宽度;
|
|
// //给sheet电子版中所有的列设置默认的列的宽度;
|
|
// sheet.getSettings().setDefaultColumnWidth(20);
|
|
// sheet.getSettings().setDefaultColumnWidth(20);
|
|
// sheet.getSettings().setDefaultRowHeight(35 * 20);
|
|
// sheet.getSettings().setDefaultRowHeight(35 * 20);
|
|
- //行号
|
|
|
|
- int firstRow = 0;
|
|
|
|
- //填充表头
|
|
|
|
- int headerColumn = 0;
|
|
|
|
- for (String key : data.keySet()) {
|
|
|
|
- Label label = new Label(headerColumn, firstRow, key, cellFormat);
|
|
|
|
- sheet.addCell(label);
|
|
|
|
- List<String> colData = data.get(key);
|
|
|
|
- for (int i = 0; i < colData.size(); i++) {
|
|
|
|
- Label lb = new Label(headerColumn, i + 1, Checker.getStringValue(colData.get(i)), cellFormat);
|
|
|
|
- sheet.addCell(lb);
|
|
|
|
- }
|
|
|
|
- headerColumn++;
|
|
|
|
- }
|
|
|
|
- // 添加汇总
|
|
|
|
- if (!Checker.isNone(collectList)) {
|
|
|
|
- for (ExcelCollectPojo pojo : collectList) {
|
|
|
|
- String[] dataArr = pojo.getDataArr();
|
|
|
|
- for (int i = 0, j = dataArr.length; i < j; i++) {
|
|
|
|
- Label lb = new Label(pojo.getCol() + i, pojo.getRow(), dataArr[i], cellFormat);
|
|
|
|
- sheet.addCell(lb);
|
|
|
|
- }
|
|
|
|
|
|
+ //行号
|
|
|
|
+// int firstRow = 0;
|
|
|
|
+// //填充表头
|
|
|
|
+// int headerColumn = 0;
|
|
|
|
+// int headerColumn2 = 0;
|
|
|
|
+// int headerColumn3 = 0;
|
|
|
|
+// for (String key : data.keySet()) {
|
|
|
|
+// Label label = new Label(headerColumn, firstRow, key, cellFormat);
|
|
|
|
+// sheet.addCell(label);
|
|
|
|
+// Label label2 = new Label(headerColumn2, firstRow, key, cellFormat);
|
|
|
|
+// sheet2.addCell(label2);
|
|
|
|
+// Label label3 = new Label(headerColumn3, firstRow, key, cellFormat);
|
|
|
|
+// sheet2.addCell(label3);
|
|
|
|
+// List<String> colData = data.get(key);
|
|
|
|
+// for (int i = 0; i < 2; i++) {
|
|
|
|
+// Label lb = new Label(headerColumn, i + 1, Checker.getStringValue(colData.get(i)), cellFormat);
|
|
|
|
+// sheet.addCell(lb);
|
|
|
|
+//// sheet2.addCell(lb);
|
|
|
|
+// }
|
|
|
|
+// for (int q = 0; q < 2; q++) {
|
|
|
|
+// Label lb = new Label(headerColumn2, q + 1, Checker.getStringValue(colData.get(2 + q)), cellFormat);
|
|
|
|
+// sheet2.addCell(lb);
|
|
|
|
+// }
|
|
|
|
+// for (int q = 0; q < 2; q++) {
|
|
|
|
+// Label lb = new Label(headerColumn3, q + 1, Checker.getStringValue(colData.get(4 + q)), cellFormat);
|
|
|
|
+// sheet3.addCell(lb);
|
|
|
|
+// }
|
|
|
|
+// headerColumn++;
|
|
|
|
+// headerColumn2++;
|
|
|
|
+// headerColumn3++;
|
|
|
|
+// }
|
|
|
|
+ // 添加汇总
|
|
|
|
+// if (!Checker.isNone(collectList)) {
|
|
|
|
+// for (ExcelCollectPojo pojo : collectList) {
|
|
|
|
+// String[] dataArr = pojo.getDataArr();
|
|
|
|
+// for (int i = 0, j = dataArr.length; i < j; i++) {
|
|
|
|
+//// Label lb = new Label(pojo.getCol() + i, pojo.getRow(), dataArr[i], cellFormat);
|
|
|
|
+//// sheet.addCell(lb);
|
|
|
|
+// Label lb2 = new Label(pojo.getCol() + i, pojo.getRow(), dataArr[i], cellFormat);
|
|
|
|
+// sheet2.addCell(lb2);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+ //开始执行写入操作
|
|
|
|
+ if (i == a - 1) {
|
|
|
|
+ workbook.write();
|
|
|
|
+ //关闭流
|
|
|
|
+ workbook.close();
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
- //开始执行写入操作
|
|
|
|
- workbook.write();
|
|
|
|
- //关闭流
|
|
|
|
- workbook.close();
|
|
|
|
|
|
+
|
|
if (ba != null) {
|
|
if (ba != null) {
|
|
try {
|
|
try {
|
|
ba.close();
|
|
ba.close();
|
|
@@ -417,7 +521,7 @@ public class ExcelDownloadSrv {
|
|
* @author Walker, added on 06/27/2019.
|
|
* @author Walker, added on 06/27/2019.
|
|
*/
|
|
*/
|
|
public OutputStream generateAndReturnMealExcelFileWithNoStyleAndCollectLocal(String fileName, String path, ExcelDataMap data, ExcelStyleMap excelStyleMap,
|
|
public OutputStream generateAndReturnMealExcelFileWithNoStyleAndCollectLocal(String fileName, String path, ExcelDataMap data, ExcelStyleMap excelStyleMap,
|
|
- List<CustomExcelItem> collectList) throws AppMessageException {
|
|
|
|
|
|
+ List<CustomExcelItem> collectList, int size) throws AppMessageException {
|
|
if (data == null || data.isEmpty()) {
|
|
if (data == null || data.isEmpty()) {
|
|
throw new AppMessageException("数据为空");
|
|
throw new AppMessageException("数据为空");
|
|
}
|
|
}
|
|
@@ -426,66 +530,130 @@ public class ExcelDownloadSrv {
|
|
WritableWorkbook workbook = null;
|
|
WritableWorkbook workbook = null;
|
|
try {
|
|
try {
|
|
// File file = new File(path);
|
|
// File file = new File(path);
|
|
- // 创建写工作簿对象
|
|
|
|
- workbook = Workbook.createWorkbook(ba);
|
|
|
|
- // 工作表
|
|
|
|
- WritableSheet sheet = workbook.createSheet(fileName, 0);
|
|
|
|
- //表头格式
|
|
|
|
- WritableCellFormat cellFormat = ExcelDownloadSrv.getWritableCellFormat();
|
|
|
|
- //数据行格式
|
|
|
|
- // 设置背景、字体颜色、对齐方式等等;
|
|
|
|
- WritableFont font2 = new WritableFont(WritableFont.ARIAL, 14, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
|
|
|
|
- WritableCellFormat cellFormat2 = new WritableCellFormat(font2);
|
|
|
|
- //设置文字居中对齐方式;
|
|
|
|
- cellFormat2.setAlignment(Alignment.CENTRE);
|
|
|
|
- //设置垂直居中;
|
|
|
|
- cellFormat2.setVerticalAlignment(VerticalAlignment.CENTRE);
|
|
|
|
- cellFormat2.setBackground(Colour.WHITE);
|
|
|
|
- cellFormat2.setBorder(Border.ALL, BorderLineStyle.THIN);
|
|
|
|
- cellFormat2.setWrap(true);
|
|
|
|
- //给sheet电子版中所有的列设置默认的列的宽度;
|
|
|
|
- sheet.getSettings().setDefaultColumnWidth(20);
|
|
|
|
- sheet.getSettings().setDefaultRowHeight(30 * 20);
|
|
|
|
- //单独应用样式
|
|
|
|
- if (excelStyleMap != null) {
|
|
|
|
- for (String column : excelStyleMap.keySet()) {
|
|
|
|
- // 指定列宽
|
|
|
|
- int styleColumnWidth = excelStyleMap.getIntValueSafely(column, ExcelStyleMap.STYLE_COLUMN_WIDTH, 0);
|
|
|
|
- List<String> columns = new ArrayList<>(data.keySet());
|
|
|
|
- for (int i = 0; i < columns.size(); i++) {
|
|
|
|
- if (columns.get(i).equals(column)) {
|
|
|
|
- sheet.setColumnView(i, styleColumnWidth);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ workbook = Workbook.createWorkbook(ba);
|
|
|
|
+
|
|
|
|
+ int list = size;
|
|
|
|
+ int a = 0;
|
|
|
|
+ if(list < 60000){
|
|
|
|
+ a = 1;
|
|
|
|
+ } else {
|
|
|
|
+ if (list % 60000 == 0) {
|
|
|
|
+ a = list / 60000;
|
|
|
|
+ } else {
|
|
|
|
+ a = list / 60000 + 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- //行号
|
|
|
|
- int firstRow = 0;
|
|
|
|
- //填充表头
|
|
|
|
- int headerColumn = 0;
|
|
|
|
- for (String key : data.keySet()) {
|
|
|
|
- Label label = new Label(headerColumn, firstRow, key, cellFormat);
|
|
|
|
- sheet.addCell(label);
|
|
|
|
- List<String> colData = data.get(key);
|
|
|
|
- for (int i = 0; i < colData.size(); i++) {
|
|
|
|
- Label lb = new Label(headerColumn, i + 1, Checker.getStringValue(colData.get(i)), cellFormat2);
|
|
|
|
- sheet.addCell(lb);
|
|
|
|
|
|
+ for (int i = 0; i < a; i++) {
|
|
|
|
+ int page = i + 1;
|
|
|
|
+
|
|
|
|
+ WritableSheet sheet = workbook.createSheet(fileName + page, 0);
|
|
|
|
+ WritableCellFormat cellFormat = ExcelDownloadSrv.getWritableCellFormat();
|
|
|
|
+ //数据行格式
|
|
|
|
+ // 设置背景、字体颜色、对齐方式等等;
|
|
|
|
+ WritableFont font2 = new WritableFont(WritableFont.ARIAL, 14, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
|
|
|
|
+ WritableCellFormat cellFormat2 = new WritableCellFormat(font2);
|
|
|
|
+ //设置文字居中对齐方式;
|
|
|
|
+ cellFormat2.setAlignment(Alignment.CENTRE);
|
|
|
|
+ //设置垂直居中;
|
|
|
|
+ cellFormat2.setVerticalAlignment(VerticalAlignment.CENTRE);
|
|
|
|
+ cellFormat2.setBackground(Colour.WHITE);
|
|
|
|
+ cellFormat2.setBorder(Border.ALL, BorderLineStyle.THIN);
|
|
|
|
+ cellFormat2.setWrap(true);
|
|
|
|
+ //给sheet电子版中所有的列设置默认的列的宽度;
|
|
|
|
+ sheet.getSettings().setDefaultColumnWidth(20);
|
|
|
|
+ sheet.getSettings().setDefaultRowHeight(30 * 20);
|
|
|
|
+ int firstRow = 0;
|
|
|
|
+ //填充表头
|
|
|
|
+ int headerColumn = 0;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ for (String key : data.keySet()) {
|
|
|
|
+ Label label = new Label(headerColumn, firstRow, key, cellFormat);
|
|
|
|
+ sheet.addCell(label);
|
|
|
|
+ List<String> colData = data.get(key);
|
|
|
|
+ for (int q = 0; q < 60000; q++) {
|
|
|
|
+ int e = 60000 * i;
|
|
|
|
+ Label lb = new Label(headerColumn, q + 1, Checker.getStringValue(colData.get(e + q)), cellFormat);
|
|
|
|
+ sheet.addCell(lb);
|
|
|
|
+ }
|
|
|
|
+ headerColumn++;
|
|
}
|
|
}
|
|
- headerColumn++;
|
|
|
|
- }
|
|
|
|
- // 添加汇总
|
|
|
|
- if (!Checker.isNone(collectList)) {
|
|
|
|
- for (CustomExcelItem item : collectList) {
|
|
|
|
- sheet.addCell(new Label(item.getColumn(), item.getRow(), item.getContent(),
|
|
|
|
- item.getCellFormat() == null ? cellFormat2 : item.getCellFormat()));
|
|
|
|
|
|
+ // 添加汇总
|
|
|
|
+ if (i == a - 1) {
|
|
|
|
+ if (!Checker.isNone(collectList)) {
|
|
|
|
+ for (CustomExcelItem item : collectList) {
|
|
|
|
+ sheet.addCell(new Label(item.getColumn(), item.getRow(), item.getContent(),
|
|
|
|
+ item.getCellFormat() == null ? cellFormat2 : item.getCellFormat()));
|
|
|
|
+
|
|
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (i == a - 1){
|
|
|
|
+ workbook.write();
|
|
|
|
+ //关闭流
|
|
|
|
+ workbook.close();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+// // 工作表
|
|
|
|
+// WritableSheet sheet = workbook.createSheet(fileName, 0);
|
|
|
|
+// //表头格式
|
|
|
|
+// WritableCellFormat cellFormat = ExcelDownloadSrv.getWritableCellFormat();
|
|
|
|
+// //数据行格式
|
|
|
|
+// // 设置背景、字体颜色、对齐方式等等;
|
|
|
|
+// WritableFont font2 = new WritableFont(WritableFont.ARIAL, 14, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
|
|
|
|
+// WritableCellFormat cellFormat2 = new WritableCellFormat(font2);
|
|
|
|
+// //设置文字居中对齐方式;
|
|
|
|
+// cellFormat2.setAlignment(Alignment.CENTRE);
|
|
|
|
+// //设置垂直居中;
|
|
|
|
+// cellFormat2.setVerticalAlignment(VerticalAlignment.CENTRE);
|
|
|
|
+// cellFormat2.setBackground(Colour.WHITE);
|
|
|
|
+// cellFormat2.setBorder(Border.ALL, BorderLineStyle.THIN);
|
|
|
|
+// cellFormat2.setWrap(true);
|
|
|
|
+// //给sheet电子版中所有的列设置默认的列的宽度;
|
|
|
|
+// sheet.getSettings().setDefaultColumnWidth(20);
|
|
|
|
+// sheet.getSettings().setDefaultRowHeight(30 * 20);
|
|
|
|
+ //单独应用样式
|
|
|
|
+// if (excelStyleMap != null) {
|
|
|
|
+// for (String column : excelStyleMap.keySet()) {
|
|
|
|
+// // 指定列宽
|
|
|
|
+// int styleColumnWidth = excelStyleMap.getIntValueSafely(column, ExcelStyleMap.STYLE_COLUMN_WIDTH, 0);
|
|
|
|
+// List<String> columns = new ArrayList<>(data.keySet());
|
|
|
|
+// for (int i = 0; i < columns.size(); i++) {
|
|
|
|
+// if (columns.get(i).equals(column)) {
|
|
|
|
+// sheet.setColumnView(i, styleColumnWidth);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ //行号
|
|
|
|
+// int firstRow = 0;
|
|
|
|
+// //填充表头
|
|
|
|
+// int headerColumn = 0;
|
|
|
|
+// for (String key : data.keySet()) {
|
|
|
|
+// Label label = new Label(headerColumn, firstRow, key, cellFormat);
|
|
|
|
+// sheet.addCell(label);
|
|
|
|
+// List<String> colData = data.get(key);
|
|
|
|
+// for (int i = 0; i < colData.size(); i++) {
|
|
|
|
+// Label lb = new Label(headerColumn, i + 1, Checker.getStringValue(colData.get(i)), cellFormat2);
|
|
|
|
+// sheet.addCell(lb);
|
|
|
|
+// }
|
|
|
|
+// headerColumn++;
|
|
|
|
+// }
|
|
|
|
+// // 添加汇总
|
|
|
|
+// if (!Checker.isNone(collectList)) {
|
|
|
|
+// for (CustomExcelItem item : collectList) {
|
|
|
|
+// sheet.addCell(new Label(item.getColumn(), item.getRow(), item.getContent(),
|
|
|
|
+// item.getCellFormat() == null ? cellFormat2 : item.getCellFormat()));
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
+// }
|
|
//开始执行写入操作
|
|
//开始执行写入操作
|
|
- workbook.write();
|
|
|
|
- //关闭流
|
|
|
|
- workbook.close();
|
|
|
|
|
|
+
|
|
|
|
+
|
|
if (ba != null) {
|
|
if (ba != null) {
|
|
try {
|
|
try {
|
|
ba.close();
|
|
ba.close();
|