.net 导出Excel

1、引用Interop.MSXML2 DLL , 2、录入XSL文件,注意Worksheet格式 請款單號
后台代码: XmlDocument myXml = new XmlDataDocument(ds); MSXML2.DOMDocument pXmlDocShow = new DOMDocumentClass(); pXmlDocShow.async = false; pXmlDocShow.loadXML(myXml.InnerXml); XmlDocument pXslDoc = new XmlDocument(); if (formType.Trim() == "CARR.FORM.2") { pXslDoc.Load(Server.MapPath("QueryFormsOfFeePC.xsl")); } else { pXslDoc.Load(Server.MapPath("QueryFormsOfFeeEP.xsl")); } MSXML2.DOMDocument pXslDocShow = new DOMDocumentClass(); pXslDocShow.async = false; pXslDocShow.loadXML(pXslDoc.InnerXml); string strTemp = pXmlDocShow.transformNode(pXslDocShow); int strTempBegin = strTemp.IndexOf(""); strTemp = strTemp.Remove(strTempBegin, strTempEnd - strTempBegin + 2); strTemp = @"" + strTemp; string _fileXls = DateTime.Now.ToString("yyyyMMdd"); Response.Clear(); Response.Buffer = true; Response.Charset = "utf-8"; Response.AddHeader("Content-Disposition", "attachment; filename=" + _fileXls + ".xls"); Response.ContentType = "application/ms-word"; Response.Write(strTemp); Response.End();

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。