• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

利用XML实现通用WEB报表打印实际使用中_xml

xml 搞代码 7年前 (2018-06-15) 163次浏览 已收录 0个评论

最近做的一个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”> &nbsp;

http://www.gaodaima.com/33495.html利用XML实现通用web报表打印实际使用中_xml

   <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&#8221;)
                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….这是为了节省每次打开页面时加载打印控件的时间,使用了一个框架网页,把打印控件放在一个单独的页面中,从而不需每次加载。

欢迎大家阅读《利用XML实现通用WEB报表打印实际使用中_xml》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:利用XML实现通用WEB报表打印实际使用中_xml

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址