update
This commit is contained in:
80
autopoi/autopoi-web/src/test/java/DaoChuBigDataTest.java
Normal file
80
autopoi/autopoi-web/src/test/java/DaoChuBigDataTest.java
Normal file
@@ -0,0 +1,80 @@
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.jeecgframework.poi.excel.ExcelExportUtil;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
import org.jeecgframework.poi.handler.inter.IExcelExportServer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: 大数据导出示例
|
||||
* @author: liusq
|
||||
* @date: 2022年1月4日
|
||||
*/
|
||||
public class DaoChuBigDataTest {
|
||||
/**
|
||||
* 导出测试方法
|
||||
* 参考:http://doc.wupaas.com/docs/easypoi/easypoi-1c10lbsojh62f
|
||||
* 参考:https://blog.csdn.net/weixin_45214729/article/details/118552415
|
||||
* @author liusq
|
||||
* @date: 2022年1月4日
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void bigDataExport() throws Exception {
|
||||
Workbook workbook = null;
|
||||
List<TestEntity> aList = new ArrayList<TestEntity>();
|
||||
ExportParams exportParams = new ExportParams();
|
||||
Date start = new Date();
|
||||
//模拟100w数据
|
||||
for(int j=0;j<1000000;j++){
|
||||
TestEntity testEntity = new TestEntity();
|
||||
testEntity.setName("李四"+j);
|
||||
testEntity.setAge(j);
|
||||
aList.add(testEntity);
|
||||
}
|
||||
//分别是 totalPage是总页数,pageSize 页码长度
|
||||
int totalPage = (aList.size() / 100000) + 1;
|
||||
int pageSize = 100000;
|
||||
/**
|
||||
* params:(表格标题属性)筛选条件,sheet值
|
||||
* TestEntity:表格的实体类
|
||||
*/
|
||||
workbook = ExcelExportUtil.exportBigExcel(exportParams,TestEntity.class, new IExcelExportServer() {
|
||||
/**
|
||||
* obj 就是下面的totalPage,限制条件
|
||||
* page 是页数,他是在分页进行文件转换,page每次+1
|
||||
*/
|
||||
@Override
|
||||
public List<Object> selectListForExcelExport(Object obj, int page) {
|
||||
//很重要!!这里面整个方法体,其实就是将所有的数据aList分批返回处理
|
||||
//分批的方式很多,我直接用了subList。然后 每批不能太大。我试了30000一批,
|
||||
//特别注意,最好每次10000条,否则,可能有内存溢出风险
|
||||
if (page > totalPage) {
|
||||
return null;
|
||||
}
|
||||
// fromIndex开始索引,toIndex结束索引
|
||||
int fromIndex = (page - 1) * pageSize;
|
||||
int toIndex = page != totalPage ? fromIndex + pageSize :aList.size();
|
||||
//不是空时:一直循环运行selectListForExcelExport。每次返回1万条数据。
|
||||
List<Object> list = new ArrayList<>();
|
||||
list.addAll(aList.subList(fromIndex, toIndex));
|
||||
return list;
|
||||
}
|
||||
}, totalPage);
|
||||
File savefile = new File("D:/excel/");
|
||||
if (!savefile.exists()) {
|
||||
savefile.mkdirs();
|
||||
}
|
||||
FileOutputStream fos = new FileOutputStream("D:/excel/ExcelExportBigData.bigDataExport.xlsx");
|
||||
workbook.write(fos);
|
||||
fos.close();
|
||||
System.out.println("耗时(秒):"+((new Date().getTime() - start.getTime())/ 1000));
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
bigDataExport();
|
||||
}
|
||||
}
|
||||
69
autopoi/autopoi-web/src/test/java/DaoChuSheetTest.java
Normal file
69
autopoi/autopoi-web/src/test/java/DaoChuSheetTest.java
Normal file
@@ -0,0 +1,69 @@
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.jeecgframework.poi.excel.ExcelExportUtil;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
import org.jeecgframework.poi.excel.entity.TemplateExportParams;
|
||||
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 参考文档:http://doc.jeecg.com/2044223
|
||||
* @author: scott
|
||||
* @date: 2020年09月16日 11:46
|
||||
*/
|
||||
public class DaoChuSheetTest {
|
||||
private static final String basePath = "G:\\needtodeplay\\autopoi-framework-sy-4.0\\autopoi-web\\src\\test\\resources\\templates\\";
|
||||
|
||||
public static ExportParams getExportParams(String name) {
|
||||
return new ExportParams(name,name,ExcelType.XSSF);
|
||||
}
|
||||
public static Workbook test() {
|
||||
/**
|
||||
* 多个Map
|
||||
* title:对应表格Title
|
||||
* entity:对应表格对应实体
|
||||
* data:Collection 数据
|
||||
*/
|
||||
List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
|
||||
for(int i=0;i<3;i++){
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("title", getExportParams("测试"+i));//表格Title
|
||||
map.put("entity",TestEntity.class);//表格对应实体
|
||||
List<TestEntity> ls=new ArrayList<TestEntity> ();
|
||||
for(int j=0;j<10;j++){
|
||||
TestEntity testEntity = new TestEntity();
|
||||
testEntity.setName("张三"+i+j);
|
||||
testEntity.setAge(18+i+j);
|
||||
ls.add(testEntity);
|
||||
}
|
||||
List<Map> ls2=new ArrayList<Map> ();
|
||||
for(int j=0;j<10;j++){
|
||||
Map map1 = new HashMap();
|
||||
map1.put("name","李四"+i+j);
|
||||
map1.put("age",18+i+j);
|
||||
ls2.add(map1);
|
||||
}
|
||||
map.put("data", ls);//ls or ls2
|
||||
listMap.add(map);
|
||||
}
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(listMap, ExcelType.XSSF);
|
||||
return workbook;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
Workbook workbook = test();
|
||||
File savefile = new File(basePath);
|
||||
if (!savefile.exists()) {
|
||||
savefile.mkdirs();
|
||||
}
|
||||
FileOutputStream fos = new FileOutputStream(basePath + "testSheet.xlsx");
|
||||
workbook.write(fos);
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
55
autopoi/autopoi-web/src/test/java/DaoChuTest.java
Normal file
55
autopoi/autopoi-web/src/test/java/DaoChuTest.java
Normal file
@@ -0,0 +1,55 @@
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.jeecgframework.poi.excel.ExcelExportUtil;
|
||||
import org.jeecgframework.poi.excel.entity.TemplateExportParams;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: TODO
|
||||
* @author: scott
|
||||
* @date: 2020年09月16日 11:46
|
||||
*/
|
||||
public class DaoChuTest {
|
||||
private static final String basePath = "G:\\needtodeplay\\autopoi-framework-sy-4.0\\autopoi-web\\src\\test\\resources\\templates\\";
|
||||
|
||||
public static TemplateExportParams getTemplateParams(String name) {
|
||||
return new TemplateExportParams(basePath + name + ".xlsx");
|
||||
}
|
||||
|
||||
public static Workbook test(String name) {
|
||||
TemplateExportParams params = getTemplateParams(name);
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Map<String, Object> lm = new HashMap<String, Object>();
|
||||
lm.put("name", "姓名1" + i);
|
||||
lm.put("isTts", i);
|
||||
lm.put("sname", "s姓名");
|
||||
lm.put("ttsContent", "ttsContent内容");
|
||||
lm.put("rate", 1000 + i);
|
||||
listMap.add(lm);
|
||||
}
|
||||
map.put("autoList", listMap);
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(params, map);
|
||||
return workbook;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
String temName = "test";
|
||||
String temNameNextM = "testNextMarge";
|
||||
Workbook workbook = test(temNameNextM);
|
||||
File savefile = new File(basePath);
|
||||
if (!savefile.exists()) {
|
||||
savefile.mkdirs();
|
||||
}
|
||||
FileOutputStream fos = new FileOutputStream(basePath + "testNew.xlsx");
|
||||
workbook.write(fos);
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
57
autopoi/autopoi-web/src/test/java/DaoChuWordTest.java
Normal file
57
autopoi/autopoi-web/src/test/java/DaoChuWordTest.java
Normal file
@@ -0,0 +1,57 @@
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.jeecgframework.poi.word.WordExportUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @Description: TODO
|
||||
* @author: scott
|
||||
* @date: 2020年09月16日 11:46
|
||||
*/
|
||||
public class DaoChuWordTest {
|
||||
private static final String basePath = "G:\\needtodeplay\\autopoi-framework-sy-4.0\\autopoi-web\\src\\test\\resources\\templates\\";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String curTime = format.format(new Date());
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
|
||||
// Map<String, Object> map1 = new HashMap<String, Object>();
|
||||
// map1.put("type", "个人所得税");
|
||||
// map1.put("presum", "1580");
|
||||
// map1.put("thissum", "1750");
|
||||
// map1.put("curmonth", "1-11月");
|
||||
// map1.put("now", curTime);
|
||||
// mapList.add(map1);
|
||||
// Map<String, Object> map2 = new HashMap<String, Object>();
|
||||
// map2.put("type", "增值税");
|
||||
// map2.put("presum", "1080");
|
||||
// map2.put("thissum", "1650");
|
||||
// map2.put("curmonth", "1-11月");
|
||||
// map2.put("now", curTime);
|
||||
// mapList.add(map2);
|
||||
map.put("taxlist", mapList);
|
||||
map.put("totalpreyear", "2660");
|
||||
map.put("totalthisyear", "3400");
|
||||
|
||||
map.put("type", "增值税");
|
||||
map.put("presum", "1080");
|
||||
map.put("thissum", "1650");
|
||||
map.put("curmonth", "1-11月");
|
||||
map.put("now", curTime);
|
||||
|
||||
//单列
|
||||
XWPFDocument document = WordExportUtil.exportWord07(basePath + "纳税信息.docx", map);
|
||||
File savefile = new File("D:\\poi");
|
||||
if (!savefile.exists()) {
|
||||
savefile.mkdirs();
|
||||
}
|
||||
FileOutputStream fos = new FileOutputStream(basePath + "纳税信息new.docx");
|
||||
document.write(fos);
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
29
autopoi/autopoi-web/src/test/java/TestEntity.java
Normal file
29
autopoi/autopoi-web/src/test/java/TestEntity.java
Normal file
@@ -0,0 +1,29 @@
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
|
||||
/**
|
||||
* @Description: TODO
|
||||
* @author: lsq
|
||||
* @date: 2021年02月02日 16:31
|
||||
*/
|
||||
public class TestEntity {
|
||||
@Excel(name = "姓名", width = 15)
|
||||
private String name;
|
||||
@Excel(name = "年龄", width = 15)
|
||||
private Integer age;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(Integer age) {
|
||||
this.age = age;
|
||||
}
|
||||
}
|
||||
BIN
autopoi/autopoi-web/src/test/resources/templates/test.xlsx
Normal file
BIN
autopoi/autopoi-web/src/test/resources/templates/test.xlsx
Normal file
Binary file not shown.
Binary file not shown.
BIN
autopoi/autopoi-web/src/test/resources/templates/纳税信息.docx
Normal file
BIN
autopoi/autopoi-web/src/test/resources/templates/纳税信息.docx
Normal file
Binary file not shown.
Reference in New Issue
Block a user