分類  >  WEB開發 >

asp網頁excel導出,如何設置為下載方式

tags:    時間:2013-12-09 22:22:45
求助:asp網頁excel導出,怎麼設置為下載方式?
下面這excel導出函數 怎麼修改能在頁面上下載呢?
求高手幫忙!!!


public void createxcel(System.Data.DataTable datatable, string filename)
         {
             HttpResponse response;
             response = HttpContext.Current.Response;
             response.Clear();
             response.Buffer = true;
 
             response.Charset = "utf-8";
 
             response.AppendHeader("Content-Disposition", "attachment;filename=" + filename + ".xls");
 
             response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");

             response.ContentType = "application/ms-excel";
 
 
             string colheaders = "", ls_items = "";
             System.Data.DataTable dt = datatable;
             DataRow[] row = dt.Select();
             int i = 0;
             int cl = dt.Columns.Count;
             for (i = 0; i < cl; i++)
             {
                 if (i == cl - 1)
                 {
                     colheaders += dt.Columns[i].Caption.ToString() + "\n";
                 }
                 else
                 {
                     colheaders += dt.Columns[i].Caption.ToString() + "\t";         
                 }          
             }
             response.Write(colheaders);
             foreach (DataRow rows in row)
             {
                 for (i = 0; i < cl; i++)

推薦閱讀文章

Bookmark the permalink ,來源:互聯網