惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Stack Overflow Blog
Stack Overflow Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
大猫的无限游戏
大猫的无限游戏
爱范儿
爱范儿
WordPress大学
WordPress大学
B
Blog RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
人人都是产品经理
人人都是产品经理
J
Java Code Geeks
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
MyScale Blog
MyScale Blog
GbyAI
GbyAI
Martin Fowler
Martin Fowler
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 聂微东
The Cloudflare Blog
L
Lohrmann on Cybersecurity
Apple Machine Learning Research
Apple Machine Learning Research
I
InfoQ
Google DeepMind News
Google DeepMind News
S
Securelist
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 【当耐特】
Latest news
Latest news
T
Threatpost
量子位
Y
Y Combinator Blog
T
Troy Hunt's Blog
Know Your Adversary
Know Your Adversary
MongoDB | Blog
MongoDB | Blog
罗磊的独立博客
博客园_首页
AWS News Blog
AWS News Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
宝玉的分享
宝玉的分享
Project Zero
Project Zero
V
Visual Studio Blog
F
Fortinet All Blogs
S
Security Affairs
The Register - Security
The Register - Security
G
Google Developers Blog
T
Tenable Blog
L
LINUX DO - 最新话题
The GitHub Blog
The GitHub Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
博客园 - 三生石上(FineUI控件)
T
The Exploit Database - CXSecurity.com
博客园 - Franky

博客园 - SOSOS's BLog

[转]视图多表 asp.net mvc3.0 在EF Code-First中自定义Model跟数据库中的表名、字段名的对应关系 征懂IOS开发的同仁,联系QQ 755414 Web前端研发工程师 Unicode To ASCII,改写至Js ExtJs Extender Controls 3.2.0 截图及下载 多余的项目外包,可长期合作.深圳的朋友(已结束,谢谢支持) webservice小解 介绍一种查找网站被上传的恶意文件的方法 2G空间免费使用,只要你有站 08年又快结束了..抱怨下!~ 基础知识要牢固..复习复习,再复习 今天去面试.net开发,感想 淘宝"新版"首页 样式在.net下测试不成功.附解决办法 在b/s开发中经常用到的javaScript技术 学习.net2.0的网站 网站广告不再影响你网站速度的代码 Ajax技术简单入门
泛型数据生成Excel
SOSOS's BLog · 2009-11-18 · via 博客园 - SOSOS's BLog

工作需要.提供下我的代码.直接上代码了,挺简单的.不需要怎么解释了

protected void btnExport_Click(object sender, EventArgs e)
        {

            List

<Bonus.Model.LogMemberBonusOut> ExportExcel = new Bonus.BLL.LogMemberBonusOut().GetList(110000, Session["strWhere"].ToString());
            DataSet ds 
= ChangeParantIDToParentExcel(ExportExcel);
            
string ExcelName = "PlayerFundOutListing_" + DateTime.Now.ToString("yyyyMMdd"+ ".xls";
            CreateExcelFromTable(ds.Tables[
0], ExcelName);
        }
#region 生成Excel的代码
        
private void CreateExcelFromTable(DataTable table, string FileName)
        {
            HttpResponse response 
= Page.Response;
            response.ContentEncoding 
= System.Text.Encoding.GetEncoding("GBK");
            response.AddHeader(
"Content-Disposition""attachment;filename=" + FileName);
            
int index = 0;
            
string headers = "";
            
for (index = 0; index < table.Columns.Count; index++)
            {
                headers 
+= table.Columns[index].ColumnName + "\t";
            }
            headers 
+= "\n";
            response.Write(headers);
            response.Flush();
foreach (DataRow row in table.Rows)
            {
                
string rowContent = "";
                
foreach (DataColumn column in table.Columns)
                {
                    rowContent 
+= row[column.ColumnName].ToString() + "\t";
                }
                rowContent 
+= "\n";
                response.Write(rowContent);
                response.Flush();
            }
            response.End();
        }
private DataSet ChangeParantIDToParentExcel(List<Bonus.Model.LogMemberBonusOut> ListData)
        {
            DataSet ds 
= new DataSet();
            DataTable tmpDt 
= new DataTable();

            tmpDt.Columns.Add(

"TranID");
            tmpDt.Columns.Add(
"Member Code");
            tmpDt.Columns.Add(
"Fund Out Amt");
            tmpDt.Columns.Add(
"Bonus");
            tmpDt.Columns.Add(
"Product");
            tmpDt.Columns.Add(
"Fund Out Date");
            tmpDt.Columns.Add(
"Status");
            tmpDt.Columns.Add(
"Verified By");
            tmpDt.Columns.Add(
"Verified Date");

            DataRow dr;

foreach (var item in ListData)
            {
                dr 
= tmpDt.NewRow();

                dr[

"TranID"= item.OrderID;
                dr[
"Member Code"= item.MemberCode;
                dr[
"Fund Out Amt"= item.OutMoney;
                dr[
"Bonus"= item.Bonus;
                dr[
"Product"= GetPname(Convert.ToInt16(item.ProductIDInfo));
                dr[
"Fund Out Date"= item.OutDate.ToString("yyyy-MM-dd hh:mm:ss");
                dr[
"Status"= item.StatusID;
                dr[
"Verified By"= item.CreateBy;
                dr[
"Verified Date"= item.CreateDate.ToString("yyyy-MM-dd hh:mm:ss").Replace("0001-01-01 12:00:00""");

                tmpDt.Rows.Add(dr);
            }

            tmpDt.AcceptChanges();
            ds.Tables.Add(tmpDt);

return ds;
        }