一。原文地址: http://blog.youkuaiyun.com/caoxiaohucxh/article/details/6554383
1.sql语句中传参
$p{参数名},注意:参数(名称必须相同)必须在报表中定义,否则报nullpointException
2.pdf中文问题
第一步:拷贝iTextAsian.jar到ireport的lib目录底下。(重启iReport)
第二步:设置PDF字体名称Tsingson和PDF文字编码格式simpleChinise。
3.web项目中添加报表
1.拷贝必须的JAR包到项目的lib下。
commons-beanutils-1.7.jar commons-collections-2.1.jar commons-digester-1.7.jar commons-javaflow-20060411.jar commons-logging-1.0.2.jar iReport.jar itext-1.3.1.jar iTextAsian.jar jasperreports-2.0.5.jar jdt-compiler-3.1.1.jar poi-3.0.1-FINAL-20070705.jar |
2.新建一个目录,用来存放设计文件,jrxml文件。
3.新建一个目录,用来存放编译后的文件。
4.编译报表。
/** * 编译报表 */ public static void compiler(String sourceFileName, String destFileName) { try { JasperCompileManager.compileReportToFile(sourceFileName, destFileName); } catch (JRException e) { e.printStackTrace(); } } |
5.填充报表
/** * 填充报表 */ public static void fill(String sourceFileName, String destFileName) { try { JasperFillManager.fillReportToFile(sourceFileName, destFileName, new HashMap(), DataBaseManager.getConnection()); } catch (JRException e) { e.printStackTrace(); } } |
6.导出HTML格式报表。
/** * 导出HTML格式报表 */ public static void exportToHTML(String sourceFileName,String destFileName) { try { JasperPrint jp = (JasperPrint) JRLoader.loadObject(sourceFileName); JRHtmlExporter export = new JRHtmlExporter(); export.setParameter(JRExporterParameter.JASPER_PRINT, jp); export.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFileName); export.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE); export.exportReport(); } catch (JRException e) { e.printStackTrace(); }
} |
5.在设计完交叉报表后运行,总是抛如下错误:
Error filling print... Error incrementing crosstab dataset
必须要把交叉报表设计在“Summary”中。
二:
http://wenku.baidu.com/view/13bfa31fa76e58fafab0034d.html
上面是初级教程
三:
http://hi.baidu.com/luodaijun/blog/item/41b86c63381816600c33fa8b.html
一个图文教程
四:
解决中文问题
解决PDF中文问题:
中文字体:STSong-Light
编码格式:UniGB-UCS2-H (Chinese Simplified)