简体   繁体   English

如何从asp.net的服务器中下载excel文件

[英]how to download excel file from server in asp.net

I want to create excel file and my web site is hosted in IIS 7 Server. 我想创建Excel文件,并且我的网站托管在IIS 7服务器中。 I do not want to use Microsoft.Office.Interop or third party licence version tool for this. 我不想为此使用Microsoft.Office.Interop或第三方许可证版本工具。

I have a scenario to create excel file which are as following: 我有一个创建Excel文件的方案,如下所示:

  1. First thing, when user clicks "export excel" button then three xsl file like: 首先,当用户单击“导出excel”按钮时,然后单击三个xsl文件,例如:

    test1.xlsx, test2.xlsx, test3.xlsx should be created and zipped in one zip folder(test) one by one, depending on the logic all three xlsx will contain their data. 应创建test1.xlsx,test2.xlsx,test3.xlsx,并将其一个一个地压缩在一个zip文件夹(测试)中,具体取决于逻辑,这三个xlsx将包含其数据。

  2. Second thing this zip folder should be downloaded on Clint system or PC. 第二件事,应该在Clint系统或PC上下载该zip文件夹。

Please provide me with a better solution or a free version of excel tool to create xsl on server . 请为我提供更好的解决方案或免费版本的excel工具,以在服务器上创建xsl。

In my ASP.Net applications I use XSLT stylesheet. 在我的ASP.Net应用程序中,我使用XSLT样式表。

Response.Clear();
Response.AddHeader("Content-Disposition", "inline; filename=filename.xls");
                        Response.ContentType = "application/vnd.ms-excel";

                        System.Xml.XmlDocument xslDoc = new System.Xml.XmlDocument();
                        xslDoc.Load(System.Web.HttpContext.Current.Server.MapPath("~\\App_Data\\my_xslt_template.xslt"));

                        System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
                        xmlDoc.LoadXml(ValuesDS.GetXml());

                        System.Xml.Xsl.XslTransform xslt = new System.Xml.Xsl.XslTransform();
                        xslt.Load(xslDoc);

                        using (System.IO.StringWriter writer = new System.IO.StringWriter())
                        {
                            xslt.Transform(xmlDoc, null, writer, null);
                            Response.Write(writer.ToString());
                        }
                        Response.End();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM