以 HTML 格式导出 iReport 图表
我正在使用 iReport 制作 JRXML 文件。为了使用 Java Struts 导出此数据,我使用以下代码。
public ActionForward reportExport(ActionMapping mapping, ActionForm form,
HttpServletRequest req, HttpServletResponse res) throws Exception {
String reportType2=req.getParameter("reporttype");
System.out.println("reportType2"+reportType2);
String filename = "slademofinalreport1.jrxml";
/*String reporttype = "pdf";*/
String reporttype = reportType2;
System.out.println(filename);
System.out.println(reporttype);
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/epim","", "");
String query="select projectname,processname,queuename,sladuedate,d.createddate,d.lastupdatedate,count(d.documentid)as numofdocuments,datediff(d.createddate,d.lastupdatedate)/count(d.documentid) as averagesla,datediff(d.sladuedate,d.createddate) as sladefined from epim.mstqueue mq,epim.userproject u,epim.documentqueuedetails d,epim.mstproject mproj,epim.mstprocess mproc where d.projectid=u.projectid and u.userid=13 and mproj.projectid=d.projectid and mproc.processid=d.processid and mq.queueid=d.queueid group by queuename ";
PreparedStatement stmt1=con.prepareStatement(query);
//stmt1.setInt(1,200);
java.sql.ResultSet rs3=stmt1.executeQuery();
/*Statement stmt1=(Statement) con.createStatement();
java.sql.ResultSet rs3= stmt1.executeQuery("select projectname,processname,queuename,sladuedate,d.createddate,d.lastupdatedate,count(d.documentid)as numofdocuments,datediff(d.createddate,d.lastupdatedate)/count(d.documentid) as averagesla,datediff(d.sladuedate,d.createddate) as sladefined from epim.mstqueue mq,epim.userproject u,epim.documentqueuedetails d,epim.mstproject mproj,epim.mstprocess mproc where d.projectid=u.projectid and u.userid=13 and mproj.projectid=d.projectid and mproc.processid=d.processid and mq.queueid=d.queueid group by queuename");*/
JRResultSetDataSource obj=new JRResultSetDataSource(rs3);
// String path = application.getRealPath("/");
JasperReport jasperReport = JasperCompileManager.compileReport("D:/subash/kmsnewwork/KMS_SUBASH/WebContent/jasperreport/"+ filename);
System.out.println("Report Compiled...");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,null,obj);
System.out.println("Report Created...");
ServletOutputStream ouputStream = res.getOutputStream();
JRExporter exporter = null;
if( "pdf".equalsIgnoreCase(reporttype) )
{
res.setContentType("application/pdf");
res.setHeader("Content-Disposition", "inline; filename=\"file.pdf\"");
exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
}
else if( "rtf".equalsIgnoreCase(reporttype) )
{
res.setContentType("application/rtf");
res.setHeader("Content-Disposition", "inline; filename=\"file.rtf\"");
exporter = new JRRtfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
}
else if( "html".equalsIgnoreCase(reporttype) )
{
exporter = new JRHtmlExporter();
exporter.setParameter(JRHtmlExporterParameter.OUTPUT_STREAM,false);
exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, new Boolean(false));
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
}
else if( "xls".equalsIgnoreCase(reporttype) )
{
res.setContentType("application/xls");
res.setHeader("Content-Disposition", "attachment; filename=\"file.xls\"");
exporter = new JRXlsExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
}
else if( "csv".equalsIgnoreCase(reporttype) )
{
res.setContentType("application/csv");
res.setHeader("Content-Disposition", "inline; filename=\"file.csv\"");
exporter = new JRCsvExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
}
try
{
exporter.exportReport();
}
catch (JRException e)
{
throw new ServletException(e);
}
finally
{
if (ouputStream != null)
{
try
{
ouputStream.close();
}
catch (IOException ex)
{
System.out.println("exception thrown");
}
}
}
/*return mapping.findForward("goLoginPage");*/
return mapping.findForward("goReportFilterPage");
}
除 HTML 外,所有导出格式均为图表。谁能帮助我吗?由于图表未使用 HTML 格式显示,我是否应该对 HTML 执行任何额外操作?
I am using the iReport to make the JRXML file. To export this data using Java Struts, I am using the following code.
public ActionForward reportExport(ActionMapping mapping, ActionForm form,
HttpServletRequest req, HttpServletResponse res) throws Exception {
String reportType2=req.getParameter("reporttype");
System.out.println("reportType2"+reportType2);
String filename = "slademofinalreport1.jrxml";
/*String reporttype = "pdf";*/
String reporttype = reportType2;
System.out.println(filename);
System.out.println(reporttype);
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/epim","", "");
String query="select projectname,processname,queuename,sladuedate,d.createddate,d.lastupdatedate,count(d.documentid)as numofdocuments,datediff(d.createddate,d.lastupdatedate)/count(d.documentid) as averagesla,datediff(d.sladuedate,d.createddate) as sladefined from epim.mstqueue mq,epim.userproject u,epim.documentqueuedetails d,epim.mstproject mproj,epim.mstprocess mproc where d.projectid=u.projectid and u.userid=13 and mproj.projectid=d.projectid and mproc.processid=d.processid and mq.queueid=d.queueid group by queuename ";
PreparedStatement stmt1=con.prepareStatement(query);
//stmt1.setInt(1,200);
java.sql.ResultSet rs3=stmt1.executeQuery();
/*Statement stmt1=(Statement) con.createStatement();
java.sql.ResultSet rs3= stmt1.executeQuery("select projectname,processname,queuename,sladuedate,d.createddate,d.lastupdatedate,count(d.documentid)as numofdocuments,datediff(d.createddate,d.lastupdatedate)/count(d.documentid) as averagesla,datediff(d.sladuedate,d.createddate) as sladefined from epim.mstqueue mq,epim.userproject u,epim.documentqueuedetails d,epim.mstproject mproj,epim.mstprocess mproc where d.projectid=u.projectid and u.userid=13 and mproj.projectid=d.projectid and mproc.processid=d.processid and mq.queueid=d.queueid group by queuename");*/
JRResultSetDataSource obj=new JRResultSetDataSource(rs3);
// String path = application.getRealPath("/");
JasperReport jasperReport = JasperCompileManager.compileReport("D:/subash/kmsnewwork/KMS_SUBASH/WebContent/jasperreport/"+ filename);
System.out.println("Report Compiled...");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,null,obj);
System.out.println("Report Created...");
ServletOutputStream ouputStream = res.getOutputStream();
JRExporter exporter = null;
if( "pdf".equalsIgnoreCase(reporttype) )
{
res.setContentType("application/pdf");
res.setHeader("Content-Disposition", "inline; filename=\"file.pdf\"");
exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
}
else if( "rtf".equalsIgnoreCase(reporttype) )
{
res.setContentType("application/rtf");
res.setHeader("Content-Disposition", "inline; filename=\"file.rtf\"");
exporter = new JRRtfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
}
else if( "html".equalsIgnoreCase(reporttype) )
{
exporter = new JRHtmlExporter();
exporter.setParameter(JRHtmlExporterParameter.OUTPUT_STREAM,false);
exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, new Boolean(false));
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
}
else if( "xls".equalsIgnoreCase(reporttype) )
{
res.setContentType("application/xls");
res.setHeader("Content-Disposition", "attachment; filename=\"file.xls\"");
exporter = new JRXlsExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
}
else if( "csv".equalsIgnoreCase(reporttype) )
{
res.setContentType("application/csv");
res.setHeader("Content-Disposition", "inline; filename=\"file.csv\"");
exporter = new JRCsvExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
}
try
{
exporter.exportReport();
}
catch (JRException e)
{
throw new ServletException(e);
}
finally
{
if (ouputStream != null)
{
try
{
ouputStream.close();
}
catch (IOException ex)
{
System.out.println("exception thrown");
}
}
}
/*return mapping.findForward("goLoginPage");*/
return mapping.findForward("goReportFilterPage");
}
All the exporting format is getting the chart except the HTML. Can anyone help me? Should I do anything extra for HTML because the chart is not getting displayed using the HTML format?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
与其他文件格式不同,图像不会嵌入 html 文件中,因此需要特别小心。
请参阅 JRHtmlExporterParameter:
“一个重要的问题是图像HTML 格式将图像存储为单独的文件,因此导出器需要知道这些图像将存储在磁盘上的位置,如果它们保留在磁盘上,则 IMAGES_URI 参数将使用包含文件名的字符串进行初始化。内存中,IMAGES_URI 必须指向能够将图像发送到浏览器的资源(例如图像 servlet,如 webapp 示例中所示)。
Unlike the other file formats, images are not imbedded in the html file, so special care is needed.
See JRHtmlExporterParameter:
"An important issue is images. The HTML format stores images as separate files, so the exporter needs to know where these images will be stored. If they are stored on disk, the IMAGES_URI parameter will be initialized with a string containing the file name on disk. If they remain in memory, IMAGES_URI must point to a resource that is able to send the images to the browser (such as an image servlet, as shown in the webapp example). "