利用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
![](https://www.aspxhome.com/images/zang.png)
![](https://www.aspxhome.com/images/jiucuo.png)
猜你喜欢
- 本文实例讲述了JS实现获取毫秒值及转换成年月日时分秒的方法。分享给大家供大家参考,具体如下:时间日期对象创建方式一var date=new
- 表空间概述Oracle的表空间属于Oracle中的存储结构,是一种用于存储数据库对象(如:数据文件)的逻辑空间,是Oracle中信息存储的最
- 本文实例讲述了python生成器用法。分享给大家供大家参考,具体如下:1. 生成器利用迭代器,我们可以在每次迭代获取数据(通过next()方
- 一、查询某个字段重复 select * from User u whe
- 有时候需要把文件中的数据放入到数组中,这里提供了一种方法,可以根据文件结尾的标记进行数据拆分,然后再把拆分的文件放入数组中# -*-codi
- 前言前段时间学习了python的多线程爬虫,当时爬取一个图片网站,开启多线程后,并没有限制线程的数量,也就是说,如果下载1000张图片,会一
- 今天写了一个放迅雷焦点广告的效果,还请大家多多指正,先附上效果图一张:相关文章:迅雷首页新闻图片轮播效果js源码首先是JS代码部分,之前一定
- 去年5月至10月间,我和雅虎口碑网的前端主管:鄢学鹍(秦歌),一起翻译了这本《JavaScript语言精粹》。原书作者是JavaScript
- 论文:Interactive Image Warping(1993年Andreas Gustafsson)算法思路:假设当前点为(x,y),
- 注意:我使用的是 Entity Framework Core 2.0 (2.0.0-preview2-final)。正式版发布时,功能可能存
- 前言Java连接MySQL数据库的方法:首先下载解压得到jar库文件,并在对应的项目中导入该库文件;然后添加JDBC;接着在Mysql数据库
- 在编写一些小程序时,我需要比较两个字符串是否相同。一开始的思路是使用ord()函数获取字符的整数表示,但是调试过后发现,ord()函数传入的
- 一。初识单元测试1)定义:单元:函数或者是类单元测试:测试类或者函数python内置的单元测试框架:unittest2)单元测试的意义好处:
- //记一个问题(已经解决2016.5.5)//在公司项目中遇见一个添加单选项的需求,采用ajax一步请求。为节约资源添加后不刷新网页,js动
- 这个效果并不难,要点是位置和比例设置,捕获鼠标位置、判断鼠标位置区域、还有onmouseover事件、onmousemove事件、onmou
- 首先,先要确定你成功安装了MySQL。1、万能启动法win+R打开运行窗口,输入 services.msc在里面找到mysql的服务名,比如
- 其主要的优点便是无需再手工添加大量的信息了,可以指定对某一个站信息的截取进行批量录入,达到省时省力的目的。与其单纯的ASP小偷程序不同的是:
- 自学Python3第5天,今天突发奇想,想用Python识别图片里的文字。没想到Python实现图片文字识别这么简单,只需要一行代码就能搞定
- 文件操作TXT文件读取txt文件读取txt文件全部内容:def read_all(txt): ...: &nbs
- 当程序中包含多个线程时,CPU 不是一直被特定的线程霸占,而是轮流执行各个线程。那么,CPU 在轮换执行线程的过程中,即从创建到消亡的整个过