润乾集算报表应用开发之Excel及PDF导出
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
定义导出 Excel 的 servlet(ExportToExcel),主要代码如下: 1、接收参数 String report = request.getParameter("rpx"); String year = request.getParameter("year");
2、读入报表 String reportFile = request.getSession().getServletContext().getRealPath("/reportFiles/" +report);
public class ExportToExcel extends HttpServlet {
/** * Constructor of the object. */
public ExportToExcel() { super();
}
/** * Destruction of the servlet. <br> */
}
/** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals
to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */
boolean graphicOut)
【附】导出 Excel 完整代码 package com.runqian.servlet;
import java.io.File; import java.io.IOException; import java.io.PrintWriter;
import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;
3、读入并计算报表 Context cxt = new Context(); ReportDefine rd = (ReportDefine)ReportUtils.read(reportFile); cxt.setParamValue("year", year); Engine engine = new Engine(rd, cxt); IReport iReport = engine.calc();
润乾集算报表应用开发之 Excel 及 PDF 导出
报表应用中有时报表只需生成指定文件,而无需在页面展现,生成的文件常见于 Excel、 PDF 等。由于报表不展现,也就无需使用报表提供的 tag,可以直接通过程序导出。集算报 表提供了丰富的 API,允许开发人员编写代码实现自己的业务逻辑。这里通过在 servlet 中导 出 Excel 为例来看一下报表不展现而直接导出的实现方式。
pageBroken)
导出 PDF 与导出 Excel 类似,调用相应导出 PDF 的方法即可,集算报表提供导出 PDF 的 方法包括: ReportUtils.exportToPDF(java.io.OutputStream os, IReport report); ReportUtils.exportToPDF(java.io.OutputStream os, IReport report, boolean pageBroken,
boolean graphicOut) ReportUtils.exportToPDF(ng.String fileName, IReport report); ReportUtils.exportToPDF(ng.String fileName, IReport report, boolean pageBroken,
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); out.print(" This is "); out.print(this.getClass()); out.println(", using the POST method"); out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close();
4、导出Excel ReportUtils.exportToExcel("D:/result.xls", iReport, true);
根 据 页 面 超 链 接 访 问 上 述 servlet , 并 传 递 参 数 , 如 : http://192.168.1.102:8080/rpx_demo/servlet/ExportToExcel?rpx=order.rpx&year=1996 即 可 直 接生成 Excel 文件,而无需展现报表。
//保证报表名称的完整性 int iTmp = 0; if( (iTmp = stIndexOf(".rpx")) <= 0 ){
report = report + ".rpx"; iTmp = 0; } String reportFile = request.getSession().getServletContext().getRealPath("/reportFiles/" +report);
}
}
to get. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */
导出的 Excel 效果如下:
集算报表提供了多个导出 Excel 的方法,除了可以导出 xls 格式,也可以导出 xlsx 格式 文件,开发人员可以根据需求选择导出 Excel 的方法: ReportUtils.exportToExcel(java.io.OutputStream os, IReport report, boolean pageBroken); ReportUtils.exportToExcel(java.io.OutputStream os, IReport report, boolean pageBroken, int
dispRatio); ReportUtils.exportToExcel(ng.String fileName, IReport report, boolean pageBroken); ReportUtils.exportToExcel(ng.String fileName, IReport report, boolean pageBroken,
import com.raqsoft.report.model.ReportDefine; import ermodel.Context; import ermodel.Engine; import ermodel.IReport; import ermodel.ParamMetaData; import com.raqsoft.report.util.ReportUtils;
public void destroy() { super.destroy(); // Just puts "destroy" string in log // Put your code here
}
/** * The doGet method of the servlet. <br> * * This method is called when a form has its tag value method equals
}
/** * Initialization of the servlet. <br> * * @throws ServletException if an error occurs */
public void init() throws ServletException { // Put your code here
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String report = request.getParameter("rpx"); String year = request.getParameter("year");
int dispRatio); ReportUtils.exportToExcel 2007(ng.String fileName,IReport report,boolean
pageBroken) ReportUtils.exportToExcel 2007(java.io.OutputStream os,IReport report,boolean
Context cxt = new Context(); try {
Rep)ReportUtils.read(reportFile);
cxt.setParamValue("year", year); Engine engine = new Engine(rd, cxt); //构造报表引擎 IReport iReport = engine.calc(); //运算报表 ReportUtils.exportToExcel("D:\\result.xls", iReport, true); } catch (Throwable e) { // TODO Auto-generated catch block e.printStackTrace(); }
2、读入报表 String reportFile = request.getSession().getServletContext().getRealPath("/reportFiles/" +report);
public class ExportToExcel extends HttpServlet {
/** * Constructor of the object. */
public ExportToExcel() { super();
}
/** * Destruction of the servlet. <br> */
}
/** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals
to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */
boolean graphicOut)
【附】导出 Excel 完整代码 package com.runqian.servlet;
import java.io.File; import java.io.IOException; import java.io.PrintWriter;
import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;
3、读入并计算报表 Context cxt = new Context(); ReportDefine rd = (ReportDefine)ReportUtils.read(reportFile); cxt.setParamValue("year", year); Engine engine = new Engine(rd, cxt); IReport iReport = engine.calc();
润乾集算报表应用开发之 Excel 及 PDF 导出
报表应用中有时报表只需生成指定文件,而无需在页面展现,生成的文件常见于 Excel、 PDF 等。由于报表不展现,也就无需使用报表提供的 tag,可以直接通过程序导出。集算报 表提供了丰富的 API,允许开发人员编写代码实现自己的业务逻辑。这里通过在 servlet 中导 出 Excel 为例来看一下报表不展现而直接导出的实现方式。
pageBroken)
导出 PDF 与导出 Excel 类似,调用相应导出 PDF 的方法即可,集算报表提供导出 PDF 的 方法包括: ReportUtils.exportToPDF(java.io.OutputStream os, IReport report); ReportUtils.exportToPDF(java.io.OutputStream os, IReport report, boolean pageBroken,
boolean graphicOut) ReportUtils.exportToPDF(ng.String fileName, IReport report); ReportUtils.exportToPDF(ng.String fileName, IReport report, boolean pageBroken,
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); out.print(" This is "); out.print(this.getClass()); out.println(", using the POST method"); out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close();
4、导出Excel ReportUtils.exportToExcel("D:/result.xls", iReport, true);
根 据 页 面 超 链 接 访 问 上 述 servlet , 并 传 递 参 数 , 如 : http://192.168.1.102:8080/rpx_demo/servlet/ExportToExcel?rpx=order.rpx&year=1996 即 可 直 接生成 Excel 文件,而无需展现报表。
//保证报表名称的完整性 int iTmp = 0; if( (iTmp = stIndexOf(".rpx")) <= 0 ){
report = report + ".rpx"; iTmp = 0; } String reportFile = request.getSession().getServletContext().getRealPath("/reportFiles/" +report);
}
}
to get. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */
导出的 Excel 效果如下:
集算报表提供了多个导出 Excel 的方法,除了可以导出 xls 格式,也可以导出 xlsx 格式 文件,开发人员可以根据需求选择导出 Excel 的方法: ReportUtils.exportToExcel(java.io.OutputStream os, IReport report, boolean pageBroken); ReportUtils.exportToExcel(java.io.OutputStream os, IReport report, boolean pageBroken, int
dispRatio); ReportUtils.exportToExcel(ng.String fileName, IReport report, boolean pageBroken); ReportUtils.exportToExcel(ng.String fileName, IReport report, boolean pageBroken,
import com.raqsoft.report.model.ReportDefine; import ermodel.Context; import ermodel.Engine; import ermodel.IReport; import ermodel.ParamMetaData; import com.raqsoft.report.util.ReportUtils;
public void destroy() { super.destroy(); // Just puts "destroy" string in log // Put your code here
}
/** * The doGet method of the servlet. <br> * * This method is called when a form has its tag value method equals
}
/** * Initialization of the servlet. <br> * * @throws ServletException if an error occurs */
public void init() throws ServletException { // Put your code here
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String report = request.getParameter("rpx"); String year = request.getParameter("year");
int dispRatio); ReportUtils.exportToExcel 2007(ng.String fileName,IReport report,boolean
pageBroken) ReportUtils.exportToExcel 2007(java.io.OutputStream os,IReport report,boolean
Context cxt = new Context(); try {
Rep)ReportUtils.read(reportFile);
cxt.setParamValue("year", year); Engine engine = new Engine(rd, cxt); //构造报表引擎 IReport iReport = engine.calc(); //运算报表 ReportUtils.exportToExcel("D:\\result.xls", iReport, true); } catch (Throwable e) { // TODO Auto-generated catch block e.printStackTrace(); }