润乾报表V4大数据api分批导出excel
来源:互联网 发布:提升搜狗关键词优化 编辑:程序博客网 时间:2024/05/22 06:34
报表在api导出excel的时候,如果遇到数据量较大时,一次性导出可能会导致内存溢出或程序卡死的情况。
那么,针对这种情况,润乾报表可以借鉴大报表的导出机制,即分批导出。 Api内可以算出总共分多少页(根据总条数和每页的条数),然后遍历页数按页导出到excel文件,且导出过程中每导出一页及时把当前页的缓存清掉,避免出现同样溢出的情况。
下面的内容为参考示例,报表总共800多条(测试用),代码中有详细的注释,当遇到类似情况时可直接参考使用:
importjava.sql.Connection;
import java.sql.Driver;
importjava.sql.DriverManager;
importcom.runqian.report4.cache.CacheManager;
importcom.runqian.report4.model.ReportDefine;
importcom.runqian.report4.model.engine.ExtCellSet;
importcom.runqian.report4.usermodel.Context;
importcom.runqian.report4.usermodel.Engine;
importcom.runqian.report4.usermodel.IReport;
importcom.runqian.report4.usermodel.PageBuilder;
importcom.runqian.report4.util.ReportUtils;
importcom.runqian.report4.view.excel.ExcelReport;
public class RunsingleRaq {
public static void main(String[] args) {
Stringlicense = "D:/server_windows.lic";
ExtCellSet.setLicenseFileName(license);
String raq = "D:/bbb.raq";
// 上下文
//Context cxt = new Context();
Connection con = null;
try {
Driver driver = (Driver) Class.forName("org.hsqldb.jdbcDriver")
.newInstance();
DriverManager.registerDriver(driver);
con = (Connection) DriverManager.getConnection(
"jdbc:hsqldb:hsql://localhost:9001/runqianDB","sa", "");
} catch (Exception e) {
e.printStackTrace();
}
// 设置默认数据源连接
//cxt.setConnection("demo", con);
ReportDefine rd = null;
PageBuilder pb = null;
try {
rd = (ReportDefine) ReportUtils.read(raq);
// 读入报表,已知(不知道共多少条就先算 然后看共几页再循环遍历)总共854条即3页 for3次即可,这里就写死了
for (int i = 0; i < 3; i++) {
Context cxt = new Context();
cxt.setConnection("demo", con);
System.out.println("----第"+(i+1)+"次算 ----");
cxt.setParamValue("startRow", 300 * i);
int endRow = 0;
if(i==2){
endRow=853;
}else{
endRow = 300 * (i + 1)-1;
}
cxt.setParamValue("endRow", endRow);
System.out.println("----起始行:"+cxt.getParamValue("startRow"));
Engine engine = new Engine(rd, cxt);// 构造报表引擎
IReport ir = engine.calc(); // 运算报表
System.out.println("---- ir数据行数:"+ir.getRowCount());
ExcelReport excel = new ExcelReport();
excel.export(ir);
excel.saveTo("D:/test"+i+".xls");
CacheManager.getInstance().deleteReportEntry(raq);//清除单个报表缓存
}
} catch (Exception e) {
e.printStackTrace();
} catch (Throwable e) {
e.printStackTrace();
}
}
}
从上面代码可以看出,通过动态传入startRow和endRow即可做到分批导出大数据报表到excel文件。
- 润乾报表V4大数据api分批导出excel
- 润乾报表v4-API导出EXCEL删除报表某一行或列
- 润乾报表v4-展现报表同时后台导出excel
- 百万数据分批导出excel
- 润乾报表Api后台导出报表组到excel
- 润乾报表v4-导出xml文件
- 润乾报表v4-自动导入excel
- 润乾报表v4-API修改报表数据源
- poi 分批导出excel
- 润乾报表v4 - 导出txt内容对齐
- 数据报表导出Excel功能
- 大数据导出excel
- NPOI大数据分批写入同个Excel
- 带query函数的润乾报表API后台导出excel空指针问题
- 润乾报表Api导出word只读
- 润乾报表api导出word
- 润乾报表v4-下拉数据集选值触发
- 润乾报表Api后台导出报表组到PDF
- fiddler抓包
- jdk环境变量配置报错
- 明德扬FPGA-培训班公开课-第08期-《算法的verilog实现》第4次课
- 关于ViewPager嵌套Fragment,Fragment使用GridView导致的问题
- 如何实现「文字输入高亮」的效果
- 润乾报表V4大数据api分批导出excel
- stm32 RTC时钟配置
- 剑指offer—扑克牌顺子
- Python20行代码实现多层神经网络的学习
- qsv视频文件转换成吗mp4视频文件
- php 运算符
- 微程序控制器之微地址的形成
- ArrayList增删底层源码阅读
- 快速了解IDEA