This commit is contained in:
2019-05-10 15:11:06 +08:00
parent 5f41a320f1
commit 3e1fc4ac19
2 changed files with 8 additions and 6 deletions

View File

@@ -4,6 +4,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.OfficeXmlFileException; import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
import org.apache.poi.ss.formula.functions.T; import org.apache.poi.ss.formula.functions.T;
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.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.File; import java.io.File;
@@ -45,7 +46,7 @@ public class ExcelKit {
//map:data,sheetName,hds,hdNames, //map:data,sheetName,hds,hdNames,
public static <T> Workbook exportExcels(List<Map<String, Object>> list) throws Exception { public static <T> Workbook exportExcels(List<Map<String, Object>> list) throws Exception {
Workbook wb = new XSSFWorkbook(); Workbook wb = new SXSSFWorkbook();
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
Map<String, Object> map = list.get(i); Map<String, Object> map = list.get(i);
Sheet sheet = wb.createSheet(); Sheet sheet = wb.createSheet();
@@ -59,8 +60,6 @@ public class ExcelKit {
nCell.setCellValue(hdNames[j]); nCell.setCellValue(hdNames[j]);
} }
//写入每一行数据---一条记录就是一行数据
@SuppressWarnings("unchecked")
List<T> data = (List<T>) map.get("data"); List<T> data = (List<T>) map.get("data");
String[] hds = (String[]) map.get("hds"); String[] hds = (String[]) map.get("hds");
dataToSheet(sheet, data, hds, 1); dataToSheet(sheet, data, hds, 1);
@@ -107,7 +106,7 @@ public class ExcelKit {
*/ */
public static <T> Workbook exportExcel(List<T> list, String[] hdNames, String[] hds) throws Exception { public static <T> Workbook exportExcel(List<T> list, String[] hdNames, String[] hds) throws Exception {
Workbook wb = new XSSFWorkbook(); Workbook wb = new SXSSFWorkbook();
Sheet sheet = wb.createSheet(); Sheet sheet = wb.createSheet();
//写入表头---Excel的第一行数据 //写入表头---Excel的第一行数据
Row nRow = sheet.createRow(0); Row nRow = sheet.createRow(0);
@@ -382,7 +381,7 @@ public class ExcelKit {
try { try {
wk = new HSSFWorkbook(fis);//if excel version 2007+ will throws OfficeXmlFileException wk = new HSSFWorkbook(fis);//if excel version 2007+ will throws OfficeXmlFileException
} catch (OfficeXmlFileException e) { } catch (OfficeXmlFileException e) {
wk = new XSSFWorkbook(fis); wk = new SXSSFWorkbook(new XSSFWorkbook(fis));
} finally { } finally {
if (fis != null) { if (fis != null) {
try { try {

View File

@@ -32,6 +32,9 @@ public class DbExecutors {
CompletableFuture<Integer> countFuture = CompletableFuture.supplyAsync(() -> dbKit.queryColumn(sqls[0], int.class)); CompletableFuture<Integer> countFuture = CompletableFuture.supplyAsync(() -> dbKit.queryColumn(sqls[0], int.class));
CompletableFuture<List<Map>> listFuture = CompletableFuture.supplyAsync(() -> dbKit.findList(sqls[1], Map.class)); CompletableFuture<List<Map>> listFuture = CompletableFuture.supplyAsync(() -> dbKit.findList(sqls[1], Map.class));
return PageBean.by(listFuture.get(), countFuture.get()); List<Map> rows = listFuture.get();
Integer total = countFuture.get();
return PageBean.by(rows, total);
} }
} }