首页 > 其他 > 详细

C# 将数据集以excel的形式输出

时间:2014-03-16 18:26:16      阅读:478      评论:0      收藏:0      [点我收藏+]

private void SaveLastMonthAuthorPays()
        {
            string fileName = "LastMonthAuthorPays.xls";

            string contentFormat = "{0}\t{1}\t{2}\t{3}\t{4}\r\n";

            DataSet ds = null;

            AuthorPayManager authorPayManager = new AuthorPayManager();
            try
            {
                ds = authorPayManager.LoadLastMonthAuthorPays();
            }
            catch (Exception ex)
            {
                //LogHelper.Warn("获取上月应支付稿酬列表时出现错误," + ex.ToString());
                AddUserLogEx("获取上月应支付稿酬列表时出现错误," + ex.ToString(), LogOPType.Insert);
                this.RedirectErrorPage("获取上月应支付稿酬列表时出现错误,请与管理员联系");
            }

            Response.ClearHeaders();
            Response.Clear();
            Response.Expires = 0;
            Response.Buffer = true;
            Response.AddHeader("Accept-Language", "zh-cn");

            Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
            Response.ContentType = "Application/ms-excel";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");

            Response.Write("支付月份\t当月支付稿酬\t半年奖励\t稿酬类型\t作家署名\r\n");
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                Response.Write(string.Format(contentFormat,
                    dr["moneytime"],//支付月份
                    dr["money"],        //当月支付稿酬
                    dr["money_level"],             //半年奖励
                    dr["nature"],        //
                    dr["aut_name"]      //作家署名
                    )
                );
            }

            Response.End();
        }

C# 将数据集以excel的形式输出,布布扣,bubuko.com

C# 将数据集以excel的形式输出

原文:http://www.cnblogs.com/niaowo/p/3603532.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!