如题!谢谢!

解决方案 »

  1.   

    使用com组件,如EXCEL.application
    hyperlink链接文件或直接输出
      

  2.   

    这个种方式用过,不过是使用的一个收费Office中间件:SOAOffice2010
      

  3.   

     Excel.Application app = new Application();
            Excel._Workbook book;
            Excel._Worksheet sheet;
            book = (Excel._Workbook)app.Workbooks.Open(strPath, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
      

  4.   

    分享网页专用导出类
    using System;
    using System.Collections;
    namespace AppFrame
    {
        /// <summary>
        /// 数据导出文件格式
        /// </summary>
        public class DataExport
        {
            private string szType = "";
            private Hashtable conType = new Hashtable();        public DataExport()
            {
                conType["xls"] = "application/ms-excel";
                conType["doc"] = "application/msword";
                conType["pdf"] = "application/pdf";
                conType["ppt"] = "application/ms-powerpoint";
                conType["zip"] = "application/zip";
                conType["rar"] = "application/rar";
                conType["gif"] = "image/gif";
                conType["jpg"] = "image/jpeg";
                conType["png"] = "image/png";
                conType["txt"] = "text/plain";
                conType["htm"] = "text/html";
                conType["xml"] = "text/xml";
            }        /// <summary>
            /// Excel文件格式
            /// </summary>
            public string xls { get { return "xls"; } }
            /// <summary>
            /// Word文件格式
            /// </summary>
            public string doc { get { return "doc"; } }
            /// <summary>
            /// PDF文件格式
            /// </summary>
            public string pdf { get { return "pdf"; } }
            /// <summary>
            /// PowerPoint文件格式
            /// </summary>
            public string ppt { get { return "ppt"; } }
            /// <summary>
            /// ZIP压缩文件格式
            /// </summary>
            public string zip { get { return "zip"; } }
            /// <summary>
            /// RAR压缩文件格式
            /// </summary>
            public string rar { get { return "rar"; } }
            /// <summary>
            /// GIF图形文件格式
            /// </summary>
            public string gif { get { return "gif"; } }
            /// <summary>
            /// JPG图形文件格式
            /// </summary>
            public string jpg { get { return "jpg"; } }
            /// <summary>
            /// PNG图形文件格式
            /// </summary>
            public string png { get { return "png"; } }
            /// <summary>
            /// TEXT文件格式
            /// </summary>
            public string txt { get { return "txt"; } }
            /// <summary>
            /// HTM网页超文本格式
            /// </summary>
            public string htm { get { return "htm"; } }
            /// <summary>
            /// XML文件格式
            /// </summary>
            public string xml { get { return "xml"; } }        /// <summary>
            /// 数据导出文件类型
            /// </summary>
            public string FileType
            {
                set { szType = value; }
                get { return szType; }
            }
            /// <summary>
            /// 数据流字串索引
            /// </summary>
            /// <param name="TypeName">导出文件类型</param>
            /// <returns>返回导出文件类型的数据流字串</returns>
            public string this[string TypeName] { get { return conType[TypeName].ToString(); } }        /// <summary>
            /// DataGrid数据导出到指定文件 如:Excel、Word
            /// </summary>
            /// <param name="objPage">Page对象</param>
            /// <param name="objGrid">DataGrid对象</param>
            public void Export2File(System.Web.UI.Page objPage, System.Web.UI.WebControls.DataGrid objGrid, DataExport de)
            {
                objPage.Response.Clear();
                objPage.Response.Buffer = false;
                objPage.Response.Charset = "GB2312";
                objPage.Response.AppendHeader("Content-Disposition", string.Format("\"attachment;filename=Export.{0}\"", de.FileType));
                objPage.Response.ContentType = de[de.FileType];
                objPage.EnableViewState = false;
                System.IO.StringWriter objStringWriter = new System.IO.StringWriter();
                System.Web.UI.HtmlTextWriter objHtmlTextWriter = new System.Web.UI.HtmlTextWriter(objStringWriter);
                objGrid.RenderControl(objHtmlTextWriter);
                objPage.Response.Write(objStringWriter.ToString());
                objPage.Response.End();
            }
        }
    }在页面调用方式
    protected void btnExport_Click(object sender, EventArgs e)
        {
            if (dgrid.Items.Count == 0) return;  //没有数据        DataExport de = new DataExport();
            de.FileType = de.xls;
            de.Export2File(this, dgrid, de);
        }
      

  5.   

    来试试这个,asp.net生成Excel文件