利用XML实现通用WEB报表打印实际使用中的例子

2016-02-19 21:45 22 1 收藏

岁数大了,QQ也不闪了,微信也不响了,电话也不来了,但是图老师依旧坚持为大家推荐最精彩的内容,下面为大家精心准备的利用XML实现通用WEB报表打印实际使用中的例子,希望大家看完后能赶快学习起来。

【 tulaoshi.com - Web开发 】

  最近做的一个B/S项目,在打印时采用了在IE中嵌入.net winform控件和XML结合的方式(参见http://www.yesky.com/20030214/1652186.shtml),在实际应用过程中,有一些心得,和大家分享。
  (一).使用通用模版格式化XML文件
  系统中共用到了三种单据,分别为出库单,入库单,送货单,因此,定义三个模版文件,格式如下:
  chukudan.xsl:
  ?xml version="1.0" encoding="GB2312"?
  xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
     xsl:template match="Bill"  
     root
   pagesetting
    landscapefalse/landscape
    paperkindCustom/paperkind
    paperwidth800/paperwidth
    paperheight600/paperheight
    paperleft0/paperleft
    paperight0/paperight
    papetop0/papetop
    papebottom0/papebottom
   /pagesetting
   reporttable
        bill x="55" y="19" border="0" bordercolor="white" maxlines="6"
    xsl:for-each select="BillMaster"
     toptable width="743"
      tr height="20"
       td width="118"  align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"车次号:/td
       td width="449"  align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="White"xsl:value-of select="SERIAL_NO" //td
       td width="35"  align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"/td
       td width="138"  align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"/td
      /tr  
     /toptable
    /xsl:for-each
    detailtable width="373"
     xsl:for-each select="BillDetail"  
      tr height="33"
       td width="90" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="White"xsl:value-of select="BILL_NO" //td
       td width="173" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"xsl:value-of select="PROD_MODEL_2" //td
       td width="55" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="White"xsl:value-of select="PROD_NUM" //td
       td width="55" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"xsl:value-of select="PIECE_NUM" //td         
      /tr 
    
     /xsl:for-each
    /detailtable
    mastertable width="370"
     xsl:for-each select="BillMaster"
      tr height="33"
       td width="90" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="White"
       /td
       td width="280" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"xsl:value-of select="ADDRESS" //td
      /tr
      tr height="33"
       td width="90" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"
       /td
       td width="90" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="White"xsl:value-of select="CONTACT_PERSON" //td
       td width="70" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"
       /td
       td width="120" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="White"xsl:value-of select="CONTACT_PHONE" //td
      /tr
      tr height="33"       
       td width="90" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="White"
       /td
       td width="280" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"xsl:value-of select="DRIVER_UNIT" //td
      /tr
      tr height="33"
       td width="90" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"
       /td
       td width="90" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"xsl:value-of select="DRIVER_NO" //td
       td width="70" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"
       /td
       td width="120" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"xsl:value-of select="DRIVER_PERSON" //td
      /tr
      tr height="33"
       td width="90" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"
       /td
       td width="90" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"xsl:value-of select="CAR_MODEL" /
       /td
       td width="70" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"
       /td
       td width="120" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"/td
      /tr
      tr height="33"
       td width="90"  align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"
       /td
       td width="280" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"xsl:value-of select="COME_TO" //td
      /tr
     /xsl:for-each
    /mastertable
   
    foottable width="743"
     xsl:for-each select="BillMaster"
      tr height="35"
       td width="90" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="White"/td
       td width="173" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"/td
       td width="55" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="White"/td
       td width="55" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"/td         
     
       td width="90"  align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"
       /td
       td width="280" align="right"  fontsize="10" fontname="宋体" fontcolor="black" b="true" i="false" u="false" bgcolor="white"xsl:value-of select="REMARK" //td
      /tr 
     /xsl:for-each
        /foottable  
    
        /bill
     /reporttable
  /root    
     /xsl:template 

  /xsl:stylesheet
  其中,toptable是表头,detailtable是表格左边的产品明细,mastertable是表格右边的运输信息等,foottable是最下面制表人等信息。

  然后,在asp.net页面中,将查询出的结果作如下转换

              '是否取得了单据
              If billInfoXml Nothing Then

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/webkaifa/)

                  billInfoDoc.LoadXml(billInfoXml)
                  'billInfoDoc.LoadXml("http://111.111.111.111/stockmg/test.xsl")
                  billTrans.Load(billFormatXmlUrl)

                  billXmlWr.Formatting = System.Xml.Formatting.Indented
                  billXmlWr.Indentation = 4
                  billXmlWr.IndentChar = " "

                  billTrans.Transform(billNav, Nothing, billXmlWr, Nothing)
                  billXmlWr.Flush()

              End If

  返回的信息用javascript代码加载到打印控件:
   parent.frames.frmhidPrint.parent.frames.frmhidPrint.print1.SetXml(xmlResult); //SetMessage(xmlResult); parent.frames.frmhidPrint.parent.frames.frmhidPrint.print1.PrintAct();

  注意,这里调用打印控件用了parent.frames....这是为了节省每次打开页面时加载打印控件的时间,使用了一个框架网页,把打印控件放在一个单独的页面中,从而不需每次加载。

   第一次发帖,包涵,呵呵。

  出处:品味技术 感受人生 BLOG

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/webkaifa/)

来源:https://www.tulaoshi.com/n/20160219/1627035.html

延伸阅读
标签: ASP
  程序代码: <script Language=VBScript   Function print_onclick //打印函数    Dim label    label=document.printinfo.label.value //获得HTML页面的数据    set objfs=CreateObject("Scripting.FileSystemObject") //创建FileSystem组件对象的实例    set objprinter=o...
标签: Web开发
  表A: 1-0-1,this is a test 3-1-1,this is a test 4-3-1,this is a test 5-3-1,this is a test 2-0-2,this is a test 上面是BBS主题列表的一个例子。一般来说,假如不是使用Oracle(Oracle 有一条查询语句可以自动生成家族树,请查阅Select ... start  with ... connect by ...语句),那么如何实现上例的列表是一件费事的工...
标签: ASP
  使用到的技术:   ASP,WSH,VBScript   文件ASPPrint.asp代码如下:   <%@ Language=VBScript %   <%        Option Explicit        Dim strSubmit          &...
标签: ASP
  <%@ LANGUAGE="VBSCRIPT" % <% ' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ' 从ADO Recordset直接生成报表 ' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ' ' 概念: ' ' 这个应用被设计成演示怎样从ADO Recordset生成报表。我们首先建立ADO Connection和 ' ...
标签: Web开发
XML数据源对象是一个ActiveX控件,允许你在XML文件和HTML页面之间操作数据。本文将向你展示如何从各种XML数据源中提取数据,以及如何使用JavaScript显示这些数据。 XML数据源对象DSO是一个微软ActiveX控件,构建在微软IE4以后的版本上。这个对象允许你把一个外部的XML文件或者嵌入HTML文件中的内容提取到HTML页面中。 ...

经验教程

788

收藏

25
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部