酷知百科網

位置:首頁 > 職場理財 > 職場就業

web頁面excel報表開發web頁面集成

操作方法

(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頁面集成