首页 > 职场理财 > 职场就业 > web页面excel报表开发web页面集成

web页面excel报表开发web页面集成

   来源:秒知站    阅读: 3.35W 次
字号:

用手机扫描二维码 在手机上继续观看

手机查看

操作方法

(01)工具/原料web页面excel报表开发工具:FineReport7.1.1大小:148.2M 适用平台:windows/linux1. 问题描述报表已集成到Web页面中,通过在页面传递参数至报表中时,会发现有时某些参数值,传递到报表中是显示为问号(???)或乱码等等一系列不能正常显示的情况。2. 问题原因这是由于浏览器和报表服务器的编码不同,字符多次进行编码转换时出现错误导致字符的显示出现乱码,尤其是中日韩文和特殊字符更容易出现乱码问题。详细的编码原理,可参考编码文档3. 解决方案在给报表服务器发送请求之前,对URL或者只对URL里面的参数名字和参数值,进行cjkEncode的编码,该方式兼容了各种不同的字符集,如ISO8859-1、 UTF-8、 GBK、 ENU_JP,尤其对中日韩文的处理采取了统一的方案。4. javascript中FineReport字符转换原理在给报表服务器发送请求之前,对URL或者只对URL里面的参数名字和参数值,进行cjkEncode的编码。源码如下:function cjkEncode(text) {if (text == null) {return"";}var newText = "";for (var i = 0; i < th; i++) {var code = CodeAt (i);if (code >= 128 || code == 91 || code == 93)  else {newText += At(i);}}return newText;}经过编码的URL或者Form表单,报表服务器智能的将这些字符正确的转换过来。cjkEncode方法在FineReport的JS库中已经预先提供了,用户只要加载了FR的JS库,就可以使用ncode对中日韩文字符进行encode,如下示例:5. 示例5.1 对URL进行cjkEncode<html><head><meta http-equiv="Content-Type" content="text/html; charset=GBK"><script type="text/javascript"  src="ReportServer?op=emb&resource="></script><Script Language="JavaScript">function frOpen() {tion=ncode("http://localhost:8075/WebReport/ReportServer?reportlet=doc/Primary/Parameter/&地区=华东");}</Script></head><body><input type="button" value="字符转换1" onclick="frOpen()"></body></html>如果只对参数值进行编辑转换,在参数后面调用ncode()方法,如:tion="http://localhost:8075/WebReport/ReportServer?reportlet=¶name="+ncode("华东");5.2 对Form表单进行cjkEncode如果是以Form表单把参数提交到报表里面,也同样需要在提交前调用cjkEncode进行编码转换,如下例子<html><head><meta http-equiv="Content-Type" content="text/html; charset=GBK"/><script type="text/javascript" src="/WebReport/ReportServer?op=emb&resource="></script><script>function autoSubmit() {var Region1 = lementById('Region');     //获取到参数Region所在文本框e = ncode(e);         //对值参数值进行编码转化 = ncode("地区");               //对参数控件名编码转换,如果参数名字为英文,则不需要此操作it();}</script><body><form name=FRform method=post action="/WebReport/ReportServer?reportlet=doc/Primary/Parameter/"><input type="text" id="Region" name="地区" value="华东"><input type="button" name="show" value= "查看" onclick="autoSubmit()"/></body></html>5.3 特殊符号处理如果在需要进行cjkEncode的URI的参数中包含特殊字符,比如%,#,$,=,&,/,?,+,@等字符时,需要在cjkEncode之后,再次调用javascript的encodeURIComponent对这些特殊字符进行编码。如参数值是”%华%“这样的字符,就需要写成encodeURIComponent(ncode("%华%")),一定要先进行cjkEncode,然后再进行encodeURIComponent,完整代码如下:<html><head><meta http-equiv="Content-Type" content="text/html; charset=GBK"><script type="text/javascript"  src="ReportServer?op=emb&resource="></script><Script Language="JavaScript">function frOpen() {tion=ncode("http://localhost:8075/WebReport/ReportServer?reportlet=doc/Primary/Parameter/&地区=") +encodeURIComponent(ncode("%华%"));}</Script></head><body><input type="button" value="字符转换1" onclick="frOpen()">

web页面excel报表开发web页面集成