在报表中,当统计报表统计的指标非常多,在页面上展现的时候,整个报表会变得非常的长,经常会通过设置滚动条拖拽来查看整个报表,当这时用不分页导出excel后,查看excel中报表被导出到一个sheet中,那么,如果让才能满足让如此繁多的指标一个一个的导出到多个sheet中呢?
其实,仔细分析整个导出过程我们可以发现,导出excel后的报表样式与页面上的报表样式保持一致,但有的时候这种一致反而不适应某些需求,怎样才能做到页面展现和导出excel样式不同呢?这里就要用到功能强大的润乾API了。
第一步:写一个java类读取报表模版
package com.runqian.test;
import com.runqian.report4.model.ReportDefine;
import com.runqian.report4.model.engine.ExtCellSet;
import com.runqian.report4.usermodel.Context;
import com.runqian.report4.usermodel.Engine;
import com.runqian.report4.usermodel.IColCell;
import com.runqian.report4.usermodel.IReport;
import com.runqian.report4.util.ReportUtils;
import com.runqian.report4.util.ReportUtils2;
public class TestExcelSaveTo {
public static void main(String[] args) throws Throwable{
//设置授权
ExtCellSet.setLicenseFileName(“C:/Program Files/reportHome/webapps/demo/WEB-INF/classes/runqianWindowServer.lic”);
//设置报表路径
String reportFile = “C:/Program Files/reportHome/webapps/demo/reportFiles/abc.raq”;
ReportDefine rd = null;
try{
读取报表模版
rd = (ReportDefine)ReportUtils.read(reportFile);
}
catch (Exception e){
e.printStackTrace();
}
第二步:设置报表列后分页属性
//取得报表总列数
int colnum = rd.getColCount();
System.out.println(colnum);
//循环设置每列的列侯分页属性
for(int i = 0; i
IColCell colCell = rd.getColCell((short)(i + 1));
colCell.setBreakPage(true);
}
//设置报表上下文路径
Context cxt = new Context();
//加载报表引擎
Engine engine = new Engine(rd, cxt);
//计算报表
IReport ir = engine.calc();
//将报表以分页的形式导出成excel
ReportUtils.exportToExcel(“C:/Program Files/reportHome/webapps/demo/reportFiles/abc.xls”, ir, true);
}
}
通过这种办法,我们还可以用API来实现导出excel的行后分页等等,大致实现思路是一样的,用读取报表后生成的IReport对象进行导出,打印等功能,即不影响页面的展现效果,又可以满足多种的导出打印需求,简单易行.