利用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
猜你喜欢
- 可以在Mac OS X 10.2.x(“Jaguar”)和以上版本上Mac OS X使用二进制安装软件包的PKG格式代替二进制分发版来安装M
- 如果我们的web应用有大量的异步请求,而这些异步请求是在web服务器认证的情况下,那当我们请求发生在服务器认证失效下,服务器自动302到登录
- 现在我将清除页面缓存的一些方法总结如下:1、在Asp页面首部加入<% Response.Buffer = True
- 上一篇介绍了 HTML5 中 Canvas 的路径,这篇将要介绍一下 Canvas&nbs
- 众所周知,FileSystemObject(fso)组件的强大功能及破坏性是它屡屡被免费主页提供商(那些支持ASP)的禁用的原因,我整理了一
- 在用到编辑器时,就会碰到一点,那就是标签的闭合问题,这个问题非常严峻,因为这可能会导致网页显示的整体样式受到破坏。这最近在PJ的functi
- 西贝做了许久的交互设计工作,每年的目标都有不同,却发现今年没有什么提高和改进的地方。也许是自己没有回头总结,总是被这样那样的借口推脱。最近休
- select for update 这个是行级锁 当 commit或者rollback时,锁释放 记得打开事务,比如jdbc里面 setAu
- 原文地址:30 Days of Mootools 1.2 Tutorials - Day 5 - Event HandlingMooTool
- 以下摘录自 oreilly.JavaScript.The.Definitive.Guide.5th.Edition.Aug.200
- 在认识ImageMagick之前,我使用的图像浏览软件是KuickShow,截图软件是KSnapShot,这两款软件都是KDE附带的软件,用
- 时下,个性ico图标却成为一些主流大牌网站提高用户体验(UE)的一个“时髦”玩法,那么,是如何在IE地址栏显示出网站的个性图标的呢?常浏览网
- 来蓝色一直都在潜水,很少写帖子,太对不起大家了.下面和大家探讨一个话题,希望能引起大家的兴趣.关于H1,一直都想和大家讨论H1用法的问题,可
- 这段时间写了很多页面代码,除了一些知识重复以外,也学到css的一些新东西,或许是旧东西,但是还是希望能对大家有用。其实在css里面有很多对a
- 昨天有位同事说,他的网页查询过程中发现普通索引和唯一索引的效率是有差别的,普通索引比唯一索引快,今天在我的虚拟机中布置了环境,测试抓图如下:
- 这一段要毕业,得折磨自己两个月....这段时间还是会摆弄了javascript的.大致在下面两个方面: 1.javascript的
- 前几天开始原来的google pr查询接口已经失效,导致很多站长工具pr查询功能不能使用原始pr查询接口:$string =&nb
- 一组常用的弹出窗口用法,以下代码集合常用的弹出窗口用法。1、最基本的弹出窗口代码<SCRIPT LANGUAGE="
- 这篇分享几个在地址栏实现的Javascript有趣效果和应用。能在浏览器地址栏实现的效果太多了,字体放大、显示所有图片、显示Cookie等等
- 要想从命令行启动mysqld服务器,你应当启动控制台窗口(或“DOS window”)并输入命令:C