API实现带有统计图超链接功能的报表html结果保存
问题的提出: 
利用API完成含统计图的报表的HTML格式导出,将报表展现结果直直接以HTML的形式保存到指定路径下。
传统方法及弊端: 
 利用润乾提供的API接口可完成报表运算结果的HTML格式导出,ReportUtils.exportToHTML方法可直接完成此功能。 
具体实现办法为: 
String reportFile =”1.raq”; 
String exportFile = “D:/tempfiles/1.html”; // 导出的文件 
//读取报表模板 
ReportDefine rd = (ReportDefine) ReportUtils.read(reportFile); 
//获取上下文 
Context context = new Context(); 
IReport report = new Engine(rd, context).calc(); 
//导出到指定的HTML 
try { 
ReportUtils.exportToHTML(exportFile, report); 
} catch (Throwable e) { 
e.printStackTrace(); 
但是,从保存的html结果可以看到此时报表统计图已经变成图片,统计图的超链接功能不能被保存。查看统计图源码可以看到,统计图对于部分的源码为<img src=”1_files/1.jpg” border=”no” height=”397″ width=”644″>,说明该方法的处理方式是将统计图作为静态图片导出。
解决办法: 
 调用ReportUtils.toHTMLString方法生成html字符串,再用输出流输出到指定的html文件中。具体实现办法如下: 
String reportFile =”1.raq”; 
String exportFile = “D:/tempfiles/1.html”; // 导出的文件 
//读取报表模板 
ReportDefine rd = (ReportDefine) ReportUtils.read(reportFile); 
//获取上下文 
Context context = new Context(); 
IReport report = new Engine(rd, context).calc(); 
//导出到指定的HTML 
try { 
String htmlText = ReportUtils.toHTMLString(report, “report1″,request); 
java.io.FileOutputStream ops = new java.io.FileOutputStream(exportFile); 
java.io.PrintWriter writer = 
new java.io.PrintWriter( 
new java.io.BufferedWriter( 
new java.io.OutputStreamWriter(out1))); 
writer.println(htmlText); 
writer.flush(); 
writer.close(); 
} catch (Throwable e) { 
e.printStackTrace(); 
利用该方式生成的html结果,统计图不是图片格式,并且支持动态统计图,统计图超链接功能。
具体示例见附件。