C#导出到excel
来源:互联网 发布:顾城英儿里面的性 知乎 编辑:程序博客网 时间:2024/05/17 00:56
#region btnDetailData_Click
/// <summary>
/// 导出数据资料到excel中 add by fuxiding 20090622
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnDetailData_Click(object sender, System.EventArgs e)
{
try
{
//Period栏位必填
if (this.ddlPeriod.SelectedValue.Equals(string.Empty))
{
UIUtility.Alert("Please choose the period!",this.Page);
return;
}
//获取页面上查询栏位的值
string sPeriod = this.ddlPeriod.SelectedValue;
string sSite = this.txtSite.Text.Trim();
string sBU = string.Empty;
if (!this.ddlBU.SelectedValue.Equals(string.Empty))
{
sBU = "'" + this.ddlBU.SelectedValue + "'";
}
D01_Shipping_by_sizeManager ShipBySizeManager=new D01_Shipping_by_sizeManager();
//获取需要导出的资料
DataTable dt = ShipBySizeManager.GetExcelData(sPeriod,sSite,sBU);
if (dt == null || dt.Rows.Count == 0)
{
UIUtility.Alert("No data,you can not export data!",this.Page);
return;
}
DataGrid dgd=new DataGrid();
dgd.DataSource=dt.DefaultView;
dgd.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgd_ItemDataBound);
dgd.DataBind();
this.Response.Clear();
this.Response.AppendHeader("Content-Disposition", "attachment; filename="+DateTime.Today.Year+DateTime.Today.Month+DateTime.Today.Day+"D01ShippingReport.xls");
this.Response.Charset="UTF7"; //输出的字符集
this.Response.ContentEncoding =System.Text.Encoding.UTF7; //编码类型
Response.ContentType = "application/vnd.ms-excel"; //输出Excel
System.IO.StringWriter tw=new System.IO.StringWriter();
HtmlTextWriter hw =new HtmlTextWriter(tw);
dgd.Visible= true;
dgd.RenderControl(hw);
dgd.Visible= false;
this.Response.Write(tw.ToString());
this.Response.End();
}
catch(Exception ex)
{
}
}
#endregion
- C#导出到EXCEL
- C#导出到EXCEL
- C#导出到EXCEL
- C#导出到EXCEL
- C#导出到excel
- c#导出到excel
- c# 导出到Excel
- C#导出到EXCEL
- C#导出到EXCEL
- C#导出到Excel
- c#导出到excel
- [转]C#导出到EXCEL
- c#导出数据到Excel
- C#数据导出到Excel
- C#数据导出到Excel
- C#中导出到Excel
- c# datagridview导出到excel
- C#导出到EXCEL(worksheet)
- log4j详细配置
- String.Format格式说明
- 关于SQL语句中的双引号、单引号和&-------asp.net
- jsp验证数字
- 用于运行 ASP.NET 的进程帐户必须具有对 IIS 元数据库
- C#导出到excel
- 摘抄:值得一读的签名
- gridview动态添加列
- 使用UltraEdit时产生备份文件
- opencms中用程序创建目录和资源文件
- 回避处理CDockablePane自动隐藏后出现的问题
- Hibernate双向关联配置用set与bag的总结
- 轻量级的Web服务——RESTful Web Services
- 软件项目管理实践之日计划