溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

利用XML如何實現(xiàn)通用WEB報表打印實際使用中的例子

發(fā)布時間:2020-10-24 17:03:17 來源:億速云 閱讀:181 作者:小新 欄目:編程語言

利用XML如何實現(xiàn)通用WEB報表打印實際使用中的例子?這個問題可能是我們?nèi)粘W(xué)習(xí)或工作經(jīng)常見到的。希望通過這個問題能讓你收獲頗深。下面是小編給大家?guī)淼膮⒖純?nèi)容,讓我們一起來看看吧!

(一).使用通用模版格式化XML文件
系統(tǒng)中共用到了三種單據(jù),分別為出庫單,入庫單,送貨單,因此,定義三個模版文件,格式如下

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是表格左邊的產(chǎn)品明細,mastertable是表格右邊的運輸信息等,foottable是最下面制表人等信息。

然后,在asp.net頁面中,將查詢出的結(jié)果作如下轉(zhuǎn)換

'是否取得了單據(jù)

 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();

注意,這里調(diào)用打印控件用了parent.frames....這是為了節(jié)省每次打開頁面時加載打印控件的時間,使用了一個框架網(wǎng)頁,把打印控件放在一個單獨的頁面中,從而不需每次加載。

感謝各位的閱讀!看完上述內(nèi)容,你們對利用XML如何實現(xiàn)通用WEB報表打印實際使用中的例子大概了解了嗎?希望文章內(nèi)容對大家有所幫助。如果想了解更多相關(guān)文章內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細節(jié)
AI