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

来源:互联网 时间:2008-09-04 14:42:00 

最近做的一个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>
  <landscape>false</landscape>
  <paperkind>Custom</paperkind>
  <paperwidth>800</paperwidth>
  <paperheight>600</paperheight>
  <paperleft>0</paperleft>
  <paperight>0</paperight>
  <papetop>0</papetop>
  <papebottom>0</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

                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

标签:
0
投稿

猜你喜欢

  • 关于Python中object类特殊方法的解释

    2023-08-31 22:19:24
  • 简述python Scrapy框架

    2022-07-13 06:19:30
  • Python Web框架Flask信号机制(signals)介绍

    2022-12-01 13:52:23
  • 去掉前面的0的sql语句(前导零,零前缀)

    2024-01-25 22:25:23
  • python中的type,元类,类,对象用法

    2022-08-24 09:54:55
  • Go语言服务器开发之客户端向服务器发送数据并接收返回数据的方法

    2024-04-27 15:39:58
  • python 2.6.6升级到python 2.7.x版本的方法

    2022-09-25 15:07:45
  • 小议JavaScript泛式框架架构的逻辑形式

    2010-07-02 12:55:00
  • 对python:threading.Thread类的使用方法详解

    2022-01-24 04:19:28
  • JavaScript队列的应用实例详解【经典数据结构】

    2024-04-16 09:53:13
  • centos7之Python3.74安装教程

    2023-10-27 15:15:24
  • SQL Server中检查字段的值是否为数字的方法

    2024-01-24 17:47:21
  • 细化解析:SQL Server 2005 数据库镜像

    2009-01-23 13:41:00
  • 通过XSL转换XML文件步骤

    2008-01-27 16:03:00
  • 基于python的Paxos算法实现

    2023-04-15 07:40:58
  • CentOS下安装MySQL5.6.10和安全配置教程详解

    2024-01-24 08:28:26
  • JavaScript Reduce使用详解

    2024-04-19 10:16:03
  • Python类中的魔法方法之 __slots__原理解析

    2023-10-01 18:49:51
  • Python日期时间Time模块实例详解

    2023-11-07 07:26:34
  • Python 使用folium绘制leaflet地图的实现方法

    2023-06-11 05:58:36
  • asp之家 网络编程 m.aspxhome.com