C# Excel的导出 经典案例
来源:互联网 发布:iphone手机解压缩软件 编辑:程序博客网 时间:2024/06/06 17:02
1、下面是导出按钮事件 ,用的是Gridview控件
#region 导出选中的会员信息
protected void btnDelete_Click(object sender, EventArgs e){
StringBuilder sb = new StringBuilder();
string[] title = { "用户名", "昵称", "手机号码", "邮箱", "会员级别" };
string th1 = "<td style=\"height:25pt; background-color:#008080; font-size:12pt; font-family:Arial; font-weight:bold; color:#ffffff; text-align:center\">{0}</td>";
string td1 = "<td style=\"height:20pt; background-color:#ccffcc; text-align:center\">{0}</td>";
string trToatal = string.Format("<tr>{0}{0}{0}{0}{0}</tr>", "<td style=\"height:20pt; background-color:#ccffcc\"></td>", "<td style=\"height:20pt; background-color:#ccffcc; color:#ff0000; font-weight:bold; font-size:11pt\">{0:0}</td>");
StringBuilder builder = new StringBuilder();
builder.Append("<html><head><meta http-equiv=\"content-type\" content=\"application/ms-excel; charset=UTF-8\"/></head><body><table border=\"1\" bordercolor=\"#D0D7E5\">");
builder.Append("<tr>");
for (int j = 0; j < title.Length; j++)
{
builder.Append(string.Format(th1, title[j]));
}
builder.Append("</tr>");
int SelectNum = 0;
for (int i = 0; i <= gvCategory.Rows.Count - 1; i++)
{
CheckBox cbox = (CheckBox)gvCategory.Rows[i].FindControl("Select");
if (cbox.Checked == true)
{
SelectNum = 1;
TUser_Info userInfo = TUser_InfoRule.GetUserID(int.Parse(gvCategory.DataKeys[i].Value.ToString()));
if (!userInfo.IsEmpty)
{
userlevelrule rule = userlevelruleRule.Getlevelid(userInfo.UserType);
builder.Append("<tr>");
builder.Append(string.Format(td1, userInfo.UserLoginName));
builder.Append(string.Format(td1, userInfo.UserName));
builder.Append(string.Format(td1, userInfo.TelephoneNumber));
builder.Append(string.Format(td1, userInfo.UserEmail));
builder.Append(string.Format(td1, rule.levelname));
builder.Append("</tr>");
}
}
}
if (SelectNum == 0)
{
RaiseErrorMessage("请勾选会员信息");
return;
}
this.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
this.Response.ContentType = "text/xls";
this.Response.AddHeader("Content-Disposition", string.Format("inline; filename=" + HttpUtility.UrlEncode(Encoding.UTF8.GetBytes("会员信息")) + "({0:yyyy-MM-dd}).xls", DateTime.Now));
this.Response.Charset = "utf-8";
this.Response.Write(builder.ToString());
this.Response.End();
}
#endregion
- C# Excel的导出 经典案例
- 【经典】C#导出Excel总结
- POI之经典案例--按列名导出excel
- C# DataGridView导出Excel的两种经典方法
- C# DataGridView导出Excel的两种经典方法
- 【项目实战】Java POI之Excel导出经典案例一
- 【项目实战】Java POI之Excel导出经典案例二
- 【项目实战】Java POI之Excel导出经典案例三
- 【项目实战】Java POI之Excel导出经典案例四
- poi导出经典案例
- C# 导出Excel的示例
- C# 导出Excel的示例
- c#导出Excel的方法
- C# 导出Excel的示例
- C#导出Excel的示例
- C# 导出Excel的示例
- C# 导出Excel的示例
- SpringMVC 导出Excel案例
- freeswitch dialplan 笔记
- C++中的rand()函数
- Android APK反编译详解(附图)
- android:shape的使用
- FTP服务器稳定性测试
- C# Excel的导出 经典案例
- Unix/Linux下的IPC---信号量集
- Android如何防止apk程序被反编译
- sql case when 语句记录
- ASP.NET MVC 入门7、Hellper与数据的提交与绑定
- 如何在source insight中使用astyle的代码整理功能
- Navicat10 mysql 触发器 应用案例
- java.lang.OutOfMemoryError: PermGen space 问题解决
- 3步让你的Ubuntu12.04支持exfat格式