根据XLS格式转换相应的xml文件

XLS格式:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
  <xsl:template match="/">
    <html>
      <body>        
        <table border="1">
          <tr bgcolor="#9acd32">
            <th>ReportName</th>
            <th>Date</th>
          </tr>
          <tr>
            <td>
              <xsl:value-of select="ValulationReport/ClientName"/>
            </td>
            <td>
              <xsl:value-of select="ValulationReport/ReportDate"/>
            </td>
          </tr>
        </table>        
          <p>Please see the attached file.Thanks</p>        
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>



XML文件:

  <? xml version="1.0" encoding="utf-8" standalone="yes" ?>
- < ValulationReport >
  < ClientName > QSDB RioVolOcean Daily Check </ ClientName >
  < ReportDate > 20141008 </ ReportDate >
  </ ValulationReport >

转换代码:

 public void Transform(string inXml, string inXsl, string outHtml)
        {
            XmlReader xslReader = null;
            Stream str = null;


            try
            {
                // Do the transform
                FileInfo f = new FileInfo(inXsl);
                if (f.Exists == false)
                {
                    throw new Exception(string.Format("Disclaimer template {0} doesn't exist.", inXsl));
                }
                xslReader = new XmlTextReader(inXsl);
                XslTransform transform = new XslTransform();
                transform.Load(xslReader);
                XPathDocument pathDoc = new XPathDocument(inXml);
                StreamWriter writer = new StreamWriter(outHtml, false, new ASCIIEncoding());
                transform.Transform(pathDoc, null, writer);
                writer.Flush();
                writer.Close();
            }
            catch (Exception ex)
            {
                string errorMes = string.Format("Exception occurred as transforming email body xsl file to html file and error message is \"{0}\"", ex.Message);
                ourLogger.Error(errorMes);
                throw new DocComposerGenerateReportException(errorMes, ex);
            }
            finally
            {
                if (xslReader != null)
                    xslReader.Close();


                if (str != null)
                    str.Close();
            }
        }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值