web頁面excel報表開發web頁面整合

來源:酷知科普網 3.23W

操作方法

(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頁面整合
熱門標籤