2010-03-31 36 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 
相关问题