2010-03-31 35 views

回答

0

您可能會考慮創建第二個頁面,該頁面顯示網格中的數據但關閉了分頁。這樣所有的數據將被導出到Excel

0

如果您從數據庫中提取所有記錄並將其存儲在本地,那麼您可能會考慮從該數據源導出數據。而不是從頁面大小的記錄中實現分頁時的數據網格。

0

//導出的實際數據集

  if (rds != null && rds.Tables.Count != 0) 
      { 

       #region WriteToTheStringBuilder 
       DataTable dt = rds.Tables[0]; 
       StringBuilder str = new StringBuilder(); 
       //first add the column names 
       for (int j = 0; j <= dt.Columns.Count - 1; j++) 
       { 
        //comm -- remove only one tab if exists from each cell 
        str.Append (dt.Columns[j].ToString() + "\t"); 
       } 
       str.AppendLine(); 
       //comm -- than add by row the whole table 

       for (int i = 0; i <= dt.Rows.Count - 1; i++) 
       { 
        for (int j = 0; j <= dt.Columns.Count - 1; j++) 
        { 
         //comm -- remove only one tab if exists from each cell 
         str.Append (Utils.Str.Str.FindAndReplace (
                         dt.Rows[i][j].ToString(), "(.*)(\t)(.*)", "$1$3") + "\t"); 
        } 

        str.AppendLine(); 
       } 
       #endregion WriteToTheStringBuilder 


       #region WriteToResponse 
       //<source>http://geekswithblogs.net/brcraju/archive/2005/07/27/48372.aspx</source> 
       HttpContext.Current.Response.Clear(); 
       HttpContext.Current.Response.ClearContent(); 
       HttpContext.Current.Response.ClearHeaders(); 
       HttpContext.Current.Response.Buffer = true; 
       HttpContext.Current.Response.ContentType = "application/vnd." + fileExtension; 
       //HttpContext.Current.Response.Write(@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">"); 

       #region IftheExportingServerIsBehindFirewall 
       bool flagUseDnsRemapping = false; 
       flagUseDnsRemapping = Convert.ToBoolean(Convert.ToInt16(Resources.GV.UseSecureConnection)); 

       if (flagUseDnsRemapping == true) 
        HttpContext.Current.Response.AddHeader("Host", Resources.GV.ServerDNSName); 

       #endregion IftheExportingServerIsBehindFirewall 
       HttpContext.Current.Response.AddHeader("content-disposition", 
       "attachment;filename=" + pageName + "." + fileExtension); 
       HttpContext.Current.Response.Charset = " "; //utf will brake thinks ... 
       HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250"); //windows-1250 
       //HttpContext.Current.Response.Cache.SetCacheability (HttpCacheability.NoCache); 

// System.IO.StringWriter stringWrite =新System.IO.StringWriter(); // System.Web.UI.HtmlTextWriter htmlWrite = // new HtmlTextWriter(stringWrite); HttpContext.Current.Response.Write(str.ToString()); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); #endregion WriteToResponse

   userObj.Mc.Msg = "Export to Excel performed successfully "; 
       return true; 
      } //eof if 
相關問題