(C#)asp.net(DataSet)导出Excel文件
2008-09-05 09:48
399 查看
public override void VerifyRenderingInServerForm(Control control)
{
//OverRide 为了使导出成Excel可行!
}
protected void CSVDownload_Click(object sender, EventArgs e)
{
Response.Clear();
DataSet dsAnalysis1;
dsAnalysis1 = creatdataset();
GridView2.DataSource = dsAnalysis1.Tables[0].DefaultView;
GridView2.DataBind();
this.GridView2.Visible = true;
Response.Clear();
Response.Charset = "GB2312";
Response.AddHeader("content-disposition", "attachment; filename=" + CSVfilename + "");
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "application/vnd.ms-excel.numberformat:@";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView2.AllowPaging = false;
GridView2.RenderControl(htmlWrite);
stringWrite.ToString().Replace(",", "~");
Response.Write(stringWrite.ToString().Replace(",", "~"));
GridView2.Visible = false;
Response.End();
}
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Attributes.Add("style", "vnd.ms-excel.numberformat: @");
}
}
}
{
//OverRide 为了使导出成Excel可行!
}
protected void CSVDownload_Click(object sender, EventArgs e)
{
Response.Clear();
DataSet dsAnalysis1;
dsAnalysis1 = creatdataset();
GridView2.DataSource = dsAnalysis1.Tables[0].DefaultView;
GridView2.DataBind();
this.GridView2.Visible = true;
Response.Clear();
Response.Charset = "GB2312";
Response.AddHeader("content-disposition", "attachment; filename=" + CSVfilename + "");
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "application/vnd.ms-excel.numberformat:@";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView2.AllowPaging = false;
GridView2.RenderControl(htmlWrite);
stringWrite.ToString().Replace(",", "~");
Response.Write(stringWrite.ToString().Replace(",", "~"));
GridView2.Visible = false;
Response.End();
}
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Attributes.Add("style", "vnd.ms-excel.numberformat: @");
}
}
}
相关文章推荐
- 关于asp.net C# 导出Excel文件打开Excel文件格式与扩展名指定格式不一致的解决办法
- 关于asp.net C# 导出Excel文件 打开Excel文件格式与扩展名指定格式不一致的解决办法
- ASP.NET(C#) DataSet数据导出到Excel
- C#导出Excel文件Demo(Asp.Net也可用)
- 关于asp.net C# 导出Excel文件 打开Excel文件格式与扩展名指定格式不一致的解决办法
- ASP.NET(C#) DataSet数据导出到Excel
- ASP.NET(C#) DataSet数据导出到Excel
- [ASP.NET-C#]将DataSet、DataTable中的数据导出为Excel的解决方法
- 将Dataset数据导出到Excel中(ASP.NET/C#)
- 关于asp.net C# 导出Excel文件 打开Excel文件格式与扩展名指定格式不一致的解决办法
- 将Dataset数据导出到Excel中(ASP.NET/C#)
- 关于asp.net C# 导出Excel文件 打开Excel文件格式与扩展名指定格式不一致的解决办法
- 将Dataset数据导出到Excel中(ASP.NET/C#)
- [原创]大量数据导出为Excel文件的问题解决(C#,ASP.NET)
- ASP.NET(C#)将DATASET导出XLS文件【1】
- ASP.NET中导出excel/word等类型文件的简单方法
- asp.net c# repeater或gridview导出EXCEL的详细代码。
- Asp.Net MVC 使用FileResult导出Excel数据文件
- 整理的 C# DataSet导出至Excel文件(2)
- asp.net C# 导出excel