Ilist导出Excel数据
来源:互联网 发布:the eric python ide 编辑:程序博客网 时间:2024/04/30 06:54
///
/// Ilist导出Excel数据
///
/// 需要传入的Ilist对象
///
public void CreateExcel
{
if (lt == null || lt.Count <= 0)
{
JavaScript.Alert("没有数据需要导出!",Page);
return ;
}
System.Reflection.PropertyInfo[] myPropertyInfo = typeof(T).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
HttpResponse resp;
resp = Page.Response;
resp.Charset = "UTF-8";
resp.ContentEncoding = System.Text.Encoding.Default;
resp.ContentType = "application/ms-excel";
resp.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8) + ".xls");
EnableViewState = false;
string colHeaders = "", Is_item = "";
int i = 0,j;
for (i = 0, j = myPropertyInfo.Length; i < j; i++)
{
System.Reflection.PropertyInfo pi = myPropertyInfo[i];
string name = pi.Name;
colHeaders += name + "/t";
}
colHeaders += "/n";
resp.Write(colHeaders);
foreach (T t in lt)
{
if (t == null)
{
continue;
}
for (i = 0, j = myPropertyInfo.Length; i < j; i++)
{
System.Reflection.PropertyInfo pi = myPropertyInfo[i];
string str = string.Format("{0}", pi.GetValue(t, null)).Replace("/n", "");
if(str=="")
{
Is_item += "/t";
}
else
{
Is_item += str + "/t";
}
}
Is_item += "/n";
resp.Write(Is_item);
Is_item = "";
}
//写缓冲区中的数据到HTTP头文件中
resp.End();
}
protected void Button1_Click(object sender, EventArgs e)
{
questions qs = new questions();
qs.qflag = 0;
int count = 0;
IList
CreateExcel(lt, "ToAskQuestions");
}
- Ilist导出Excel数据
- C#导出泛型IList到Excel
- ASP.NET C# IList/dataset导出excel
- excel导入、导出数据
- 数据导出excel文件
- Excel数据导入导出
- 数据导出至excel
- C#Excel数据导出
- C# Excel数据导出
- 导出页面数据Excel
- List导出数据Excel
- 数据导出到Excel
- Excel导出数据
- wimform 导出数据 excel
- sql数据导出Excel
- 数据导出Excel表
- 将数据导出EXCEL
- 数据导出Excel
- GridView当数据源为空时如何实现显示表头
- 所见即所得的导出到excel的方法
- 数据绑定控件加入序号
- IbatisNet maps中select,insert,update中动态字段
- Ilist 转换成 DataSet
- Ilist导出Excel数据
- 'asp 获取网页地址及参数
- Iframe自适应其加载的内容高度
- .net中如何用webconfig文件单独对某个文件夹验证?
- 在asp.net使用web.config身份验证
- webconfig身份验证
- 利用web.config来实现登陆验证
- ASP.NET用户名及密码放在Web.config中的Forms验证
- JS中的setTimeout和setInterval的区别