我有一个问题,而从电网到excel.I显示数据已经实现分页,问题是显示只出口到Excel中并不是所有的页面的页面。
你可能会考虑创建一个网格显示数据的第二页,但是与页面关闭。这样,所有的数据将被导出到Excel
如果从数据库读取的所有记录,并将其存储在本地,那么你可以考虑将数据从源出口。不从DataGrid分页实现它包含的页面大小的记录。
//导出实际数据集
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 = //新的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