简体   繁体   中英

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. I do not want to use Microsoft.Office.Interop or third party licence version tool for this.

I have a scenario to create excel file which are as following:

  1. First thing, when user clicks "export excel" button then three xsl file like:

    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.

  2. Second thing this zip folder should be downloaded on Clint system or PC.

Please provide me with a better solution or a free version of excel tool to create xsl on server .

In my ASP.Net applications I use XSLT stylesheet.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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