存在数据量非常大场景,如代码示例和附件为1W条 实际场景可能超千万,数据按批给过来,可能为1000条一个批次,且需要结果按照条数进行分文件生成
最终效果如附件,简化模板如附件,数据按1000条进行批次提供,最终生成结果文件
import com.alibaba.fastjson.JSONObject;
import com.grapecity.documents.excel.*;
import java.io.*;
import java.util.*;
public class gcexcelSplit {
static class DataSourceData{
CustInfo custInfo;
Manager manager;
Linker linker;
List<Bu> bu;
String buFeeAmtTotal = "1000";
String buRebateAmtTotal ="0";
String buShouldPayAmountTota="1000";
List<ExpressWaybill> expressWaybill;
List<JSONObject> expressFastWaybill;
SumInfo sumInfo;
}
static class ExpressWaybill{
String orderNo = "SF001";
String itemNo ;
public String getItemNo() {
return itemNo;
}
public void setItemNo(String itemNo) {
this.itemNo = itemNo;
}
}
static class SumInfo{
String expressWaybillFeeAmtTotal = "1000";
String expressWaybillRebateAmtTotal ="0";
String expressWaybillShouldPayAmountTotal= "1000";
String expressFastWaybillFeeAmtTotal= "1000";
String expressFastWaybillRebateAmtTotal="0";
String expressFastWaybillShouldPayAmountTotal= "1000";
}
static class Manager{
String name = "XXX";
String mobile = "qwe";
}
static class Linker{
String name = "XXX";
String mobile = "qwe";
String email = "asda";
}
static class CustInfo{
String custName ="xxx";
String custCode = "9700";
String period = "202504";
String total = "1000";
String shouldPayAmount = "1000";
String sfCompanyName = "XXX";
String sfBankName = "YYY";
String sfBankAccount = "ZZZ9900";
}
static class Bu{
String name;
String feeAmt;
String rebateAmt;
String shouldPayAmount;
public Bu(String name, String feeAmt, String rebateAmt, String shouldPayAmount) {
this.name = name;
this.feeAmt = feeAmt;
this.rebateAmt = rebateAmt;
this.shouldPayAmount = shouldPayAmount;
}
}
public static void main(String[] args) throws IOException {
System.out.println(System.currentTimeMillis());
Workbook workbook2 = new Workbook();
workbook2.open("E:\\template.xlsx");
DataSourceData ds = new DataSourceData();
ds.sumInfo = new SumInfo();
ds.linker = new Linker();
ds.manager = new Manager();
ds.custInfo = new CustInfo();
List<Bu> bus = new ArrayList<>();
bus.add(new Bu("SF","1000","0","1000"));
bus.add(new Bu("KY","1000","0","1000"));
ds.bu = bus;
List<ExpressWaybill> expressWaybill = new ArrayList<>();
for(int i=0;i<10000;i++){
ExpressWaybill data = new ExpressWaybill();
data.setItemNo(i+"");
expressWaybill.add(data);
}
ds.expressWaybill = expressWaybill;
List<JSONObject> expressFastWaybill = new ArrayList<>();
ds.expressFastWaybill = expressFastWaybill;
workbook2.addDataSource("ds",ds);
workbook2.processTemplate();
workbook2.save("E:\\templateRes2.xlsx");
System.out.println(System.currentTimeMillis());
}
}
|
|