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

推荐订阅源

量子位
S
Securelist
MyScale Blog
MyScale Blog
Jina AI
Jina AI
罗磊的独立博客
The Cloudflare Blog
美团技术团队
博客园 - 叶小钗
阮一峰的网络日志
阮一峰的网络日志
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
雷峰网
雷峰网
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
大猫的无限游戏
大猫的无限游戏
博客园 - Franky
博客园 - 聂微东
Y
Y Combinator Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MongoDB | Blog
MongoDB | Blog
T
Tailwind CSS Blog
Attack and Defense Labs
Attack and Defense Labs
博客园_首页
Latest news
Latest news
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Hacker News
The Hacker News
G
GRAHAM CLULEY
Simon Willison's Weblog
Simon Willison's Weblog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
U
Unit 42
D
Docker
Webroot Blog
Webroot Blog
N
Netflix TechBlog - Medium
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LINUX DO - 最新话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
B
Blog
Recent Announcements
Recent Announcements
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
Security Latest
Security Latest
V2EX - 技术
V2EX - 技术
N
News | PayPal Newsroom
Microsoft Security Blog
Microsoft Security Blog

博客园 - 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;
        }