谁知道如何使用iReport 和jasper生成报表(SQL传参数及中文文件名)
1个回答
展开全部
1.首先下载所需要的工具和架包。这里不在多说了。2.这里只介绍几个难点。1)用ireport创建完成jrxml文件后,到ireport的安装目录找到相应的jasper文件,然后放到项目的一个目录中。(由于让程序每次都编译jrxml很浪费时间,再说模板也不容易改变,建议只编译一次就OK)2)使用代码如下Session session = HibernateUtil.currentSession();
Connection con = session.connection(); //得到链接
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQ ry("select * from applications_list where app_id='" +appId+"'"); //用数据集传入带参数的SQL语句
System.out.println("select * from applications_list where appl_list_id='" +appId+"'");
String appPath = req st.getSession().getServletContext().getRealPath("/"); //得到以便于好的jasper文件
if (appPath.lastIndexOf("\\") != appPath.length() - 1)appPath += "\\";
String reportFileName = appPath+ "jasper\\untitled_report_1.jasper";
Map parameters = new HashMap();
parameters.put("Title", "设备申请列表");//注意可以有很多个参数
JasperPrint jasperPrint = JasperFillManager.fillReport(reportFileName, parameters, new JRResultSetDataSource(rs));
JRRtfExporter exporter = null;
exporter = new JRRtfExporter();
response.setContentType("text/html; charset=UTF-8");
response.setContentType("application/msword");
String applicatiosname = ToUTF8.toUtf8String("设备申请单"); //处理下载后文件名中文问题
response.setHeader("Content-disposition","attachment;filename="+applicatiosname+".doc");
exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8");
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, response.getOutputStream());
exporter.exportReport();? * 返回字符编码UTF-8 */
p lic static String toUtf8String(String s) {
StringB?r sb = new StringB?r();
Connection con = session.connection(); //得到链接
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQ ry("select * from applications_list where app_id='" +appId+"'"); //用数据集传入带参数的SQL语句
System.out.println("select * from applications_list where appl_list_id='" +appId+"'");
String appPath = req st.getSession().getServletContext().getRealPath("/"); //得到以便于好的jasper文件
if (appPath.lastIndexOf("\\") != appPath.length() - 1)appPath += "\\";
String reportFileName = appPath+ "jasper\\untitled_report_1.jasper";
Map parameters = new HashMap();
parameters.put("Title", "设备申请列表");//注意可以有很多个参数
JasperPrint jasperPrint = JasperFillManager.fillReport(reportFileName, parameters, new JRResultSetDataSource(rs));
JRRtfExporter exporter = null;
exporter = new JRRtfExporter();
response.setContentType("text/html; charset=UTF-8");
response.setContentType("application/msword");
String applicatiosname = ToUTF8.toUtf8String("设备申请单"); //处理下载后文件名中文问题
response.setHeader("Content-disposition","attachment;filename="+applicatiosname+".doc");
exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8");
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, response.getOutputStream());
exporter.exportReport();? * 返回字符编码UTF-8 */
p lic static String toUtf8String(String s) {
StringB?r sb = new StringB?r();
ZESTRON
2024-09-04 广告
2024-09-04 广告
在Dr. O.K. Wack Chemie GmbH,我们高度重视ZESTRON的表界面分析技术。该技术通过深入研究材料表面与界面的性质,为提升产品质量与可靠性提供了有力支持。ZESTRON的表界面分析不仅涵盖了相变化、化学反应、吸附与解吸...
点击进入详情页
本回答由ZESTRON提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询