网站建设用户需求分析,自己做的网站能在线支付,购物网站设计意义,如何查网站空间一、 介绍ScriptX控件对于B/S架构的项目中#xff0c;Web打印最是让程序员头痛的技术#xff0c;在这次项目中运用了第三方控件ScriptX解决了此技术包括各种汇总表#xff0c;详细清单等等#xff0c;但最大弊端就是打印的格式是死的#xff0c;你要打印出怎样的格式必…一、 介绍ScriptX控件 对于B/S架构的项目中Web打印最是让程序员头痛的技术在这次项目中运用了第三方控件ScriptX解决了此技术包括各种汇总表详细清单等等但最大弊端就是打印的格式是死的你要打印出怎样的格式必须自己来做还有就是打印分页它是按你设置的纸张大小来分的所以必须人为控制ScriptX控件所需文件ScriptX.cab。ScriptX下载地址http://www.meadroid.com/scriptx/freedep.asp 打印功能使用 ⑴ 用户在客户端单击“打印”按钮第一次使用打印会弹出如下对话框 ⑵ 单击“是”按钮此时会把控件ScriptX下载到本机 ⑶ 在打印窗口中有大标题、打印条件、打印列表单击“打印”按钮进入打印浏览界面。 ⑷ 单击“Print”按钮听打印机声音响起。 二、 一个简单的ScriptX控件使用实例 1界面文件 WebExample.aspx 其中kg.css是界面样式在这里就不介绍了 % Page languagec# CodebehindWebExample.aspx.cs AutoEventWireupfalse InheritsWebPrint.WebExample % !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0 Transitional//EN HTML HEAD title一个简单的ScriptX打印/title meta nameGENERATOR ContentMicrosoft Visual Studio .NET 7.1 meta nameCODE_LANGUAGE ContentC# meta namevs_defaultClientScript contentJavaScript meta namevs_targetSchema contenthttp://schemas.microsoft.com/intellisense/ie5 LINK hrefkg.css typetext/css relstylesheet /HEAD body MS_POSITIONINGGridLayout form idWebExample methodpost runatserver TABLE width100% height100% tr td height100 /td /tr tr td styleHEIGHT: 14px aligncenter div iddivTableResult namedivTableResult asp:Label idLabel1 runatserver Width232px Height32px Font-SizeLarge欢迎使用ScriptX打印/asp:Label /div /td /tr tr td aligncenter valigntop div iddivChartResult namedivChartResult asp:Image idImage1 runatserver ImageUrlwin2000.gif/asp:Image /div /td /tr tr td aligncenter valigntop input idbtnPrint styleWIDTH: 32px; HEIGHT: 19px οnclickprintResult(); typebutton size1 value打印 namebtnPrint /td /tr /TABLE /form script languagejavascript function printResult() { //针对不同模块设置打印参数 var title ScriptX打印;//报表名称 var orien true;//打印页面方向true:纵向打印/false横向打印 //参数设置结束 var strURL; title escape(title); //condition escape(condition); strURL printContainer2.aspx?titletitleorienorien; window.open(strURL,printResult,height600, width800, top0, left50,toolbarno , menubarno, scrollbarsyes, resizableno, locationno, statusno); } /script /body /HTML 说明 ⑴ div iddivTableResult namedivTableResult和div iddivChartResult namedivChartResult 是在printContainer2.aspx文件中定义的传值标签因此必须要有。 ⑵ printResult方法用来声明传值内容具体在方法中已说明 2打印界面 printContainer2.aspx 其中print.css是打印样式就不介绍了 % Page languagec# CodebehindprintContainer2.aspx.cs AutoEventWireupfalse InheritsWebPrint.printContainer2 % !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0 Transitional//EN % string title 查询打印; ‘用于title获取标题 if(Request.QueryString[title].ToString().Trim()!){ title Request.QueryString[title].ToString().Trim(); } ‘用于orientation获取打印页面方向true:纵向打印/false横向打印 string orientation true; if(Request.QueryString[orien].ToString().Trim()!){ orientation Request.QueryString[orien].ToString().Trim(); } % html head titleScriptX 打印/title meta nameGENERATOR ContentMicrosoft Visual Studio .NET 7.1 meta nameCODE_LANGUAGE ContentC# meta namevs_defaultClientScript contentJavaScript meta http-equivcontent-type contenttext/html; charsetgb2312 meta namevs_targetSchema contenthttp://schemas.microsoft.com/intellisense/ie5 link hrefkg.css relstylesheet typetext/css link hrefprint.css relstylesheet typetext/css mediaprint script FORdocument eventonclick if(event.srcElement.tagNameA){ //alert(a click!); event.cancelBubble true; } /script style typetext/css a:link {text-decoration:none} a:visited {text-decoration:none} a:active {text-decoration:none} a:hover {text-decoration:none} A { COLOR: #000000;TEXT-DECORATION: none; FONT-SIZE: 8pt;FONT-FAMILY: ;} /style /head body MS_POSITIONINGGridLayout !--这里调用控件ScriptX.cab-- object idfactory viewastext styledisplay:none classidclsid:1663ed61-23eb-11d2-b92f-008048fdd814 codebaseScriptX.cab#Version6,1,431,2 /object SCRIPT defer //用于设置打印参数 function printBase() { factory.printing.footer b ScriptX 打印 b //页眉 factory.printing.footer //页脚 factory.printing.portrait %orientation% //true为纵向打印flase为横向打印 factory.printing.leftMargin 1.5 //左页边距 factory.printing.topMargin 0.5 //上页边距 factory.printing.rightMargin 0.5 //右页边距 factory.printing.bottomMargin 1.0 //下页边距 } /SCRIPT table width100% border0 cellspacing0 cellpadding0 aligncenter bordercolor#FFFFFF tr bordercolor#FFFFFF td table width70% border0 cellspacing0 cellpadding2 aligncenter tr td aligncenterfont size5 face宋体bdiv namedivTitle iddivTitle/div/b/font/td /tr tr td aligncenter div iddivReport namedivReport input typebutton namecmdPRINT idcmdPRINT οnclickprintReport() value打印 nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; input typebutton οnclickwindow.close(); value关闭 /div /td /tr /table /td /tr /table table width100% border0 cellspacing0 cellpadding2 aligncenter trtd aligncenter !-- 用于显示divTableContainer标签的值 -- div iddivTableContainer namedivTableContainer/div /td/tr trtd aligncenter !-- 用于显示divChartContainer标签的值 -- div iddivChartContainer namedivChartContainer/div /td/tr /table /body script languagejavascript //使界面最大化 maxWin(); var needcon; document.all.divTitle.innerText unescape(%title%); //用于把父窗体的divTableResult和divChartResult标签的值分别转入divTableContainer 和divChartContainer标签中 var tableContent window.opener.document.all.divTableResult.innerHTML; tableContent replaceAll(tableContent,A ,span ); tableContent replaceAll(tableContent,/A ,/span ); tableContent replaceAll(tableContent,a ,span ); tableContent replaceAll(tableContent,/a ,/span ); tableContent replaceAll(tableContent,input ,font ); tableContent replaceAll(tableContent,INPUT ,font ); document.all.divTableContainer.innerHTML tableContent; document.all.divChartContainer.innerHTML window.opener.document.all.divChartResult.innerHTML; //用于调用设置打印参数的方法和显示预览界面 function printReport(){ printBase(); //window.print(); factory.printing.Preview(); } function replaceAll( str, from, to ) { var idx str.indexOf( from ); while ( idx -1 ) { str str.replace( from, to ); idx str.indexOf( from ); } return str; } function maxWin() { var aw screen.availWidth; var ah screen.availHeight; window.moveTo(0, 0); window.resizeTo(aw, ah); } /script /html 三、 参考文件源代码