导出excel页签名称设置

  当前支持导出excelwordpdf类型文件的功能。其中导出的excel名称与报表名称相同。并且导出的excel如果执行分页功能,会分成多个sheet页面。每页的页签也是报表名与数字的结合。例如:报表名为cece.raq导出的excel页签为cece1cece2…等。

客户需求:导出excel页签按照默认的excel页签名sheet1sheet2…等。可以通过Api设置导出excel

 

     第一步:建立报表

添加一张报表设置arg1~arg4四个参数。分别将参数赋值到单元格。添加一个参数模板用于传参。如图一。

图一

     第二步:定义Api

<%@ page contentType=”text/html;charset=GBK”%>

<%@ page import=”com.runqian.report4.usermodel.*”%>

<%@ page import=”java.io.File”%>

<%@ page import=”com.runqian.report4.util.*”%>

<%@ page import=”com.runqian.report4.view.excel.ExcelReport”%>

<%@ page import=”com.runqian.report4.model.*”%>

<%@ page import=”java.io.*”%>

<%@ page import=”java.util.*”%>

<%@ taglib uri=”/WEB-INF/runqianReport4.tld” prefix=”report”%>

<html>

         <body topmargin=0 leftmargin=0 rightmargin=0 bottomMargin=0>

                   <%

                            request.setCharacterEncoding( “GBK” );

                   String arg1=null;

           String arg2=null;

           String arg3=null;

            String arg4=null;

String reportParamsId=request.getParameter(“reportParamsId”); //取得参数缓存的标识号

//从参数缓存池中取得的参数保存于一个Hashtable

System.out.println(“reportParamsId====“+reportParamsId);

Hashtable params = null;

if(!”".equals(reportParamsId) && reportParamsId != null){

params = com.runqian.report4.view.ParamsPool.get( reportParamsId );

arg1= (String) params.get(“arg1″);

arg2= (String) params.get(“arg2″);

arg3= (String) params.get(“arg3″);

arg4= (String) params.get(“arg4″);

 out.println(“导出exceld:\\test.xls”);

 }

                   String path= “E:/reporthome/webapps/demo/reportFiles/cece.raq”;

                            Context cxt = new Context(); //构建报表引擎计算环境               

                            cxt.setParamValue(“arg1″,arg1);

                       cxt.setParamValue(“arg2″,arg2);

                       cxt.setParamValue(“arg3″,arg3);

                       cxt.setParamValue(“arg4″,arg4);

                            ReportDefine rd = (ReportDefine) ReportUtils.read(path);//读取报表

                       Engine engine = new Engine(rd, cxt); //构造报表引擎

                            IReport iReport = engine.calc(); //运算报表

                            //定义导出excelreport对象

                            try {

                                     PageBuilder pageBuilder = new PageBuilder(iReport);

                                     ExcelReport er = new ExcelReport();

                                     //输出不分页的报表对象,第一个参数为sheet的名字

                                     //excelReport.export(“订单明细“,iReport);

                            //生成excel文件,保存在d

                                     er.export(“sheet”, pageBuilder);

                                     er.saveTo(“d:\\test.xls”);

                            } catch (Throwable e) {

                            }

                   %>

         </body>

</html>

 

 

通过上述代码定义的jsp,分布报表可以在指定路径生成excel  er.saveTo(“d:\\test.xls”);

 

第三步:Tool.jsp的传参修改

String reportParamsId=request.getParameter(“reportParamsId”); //取得参数缓存的标识号

String url=”http://127.0.0.1:6001/demo/jsp/sheet.jsp?reportParamsId=”+reportParamsId;

System.out.println(“url===>”+url);

%>

 

<div class=”btnBar”>

  <ul class=”left”>

    <!–<li class=”borderRight submitLi” onClick=”_submitTable( report1 );return false;” href=”#”> <a title=”提交” href=”#” class=”submit”></a></li>–>

    <li class=”toggleBg borderRight”>

      <ul class=”fileOper”>

<li><a class=”ICOhover” href=”#” onClick=”report1_print();return false;”><span title=”打印” class=”print”></span></a></li>

<li><a class=”ICOhover” href=”#” onClick=”window.open(‘<%=url%>’,”,’width=40%,height=40%,scrollbars=yes,status=yes’)”><span title=”导出excel” class=”excel”></span></a></li>

<li><a class=”ICOhover” href=”#” onClick=”report1_saveAsPdf();return false;”><span title=”导出pdf” class=”pdf”></span></a></li>

 

通过上述代码修改tool.jspexcel导出按钮改变为Api导出。并传参。

 

第四步:发布报表执行导出excel

 

热门文章