当前位置:编程学习 > C#/ASP.NET >>

将Repeater里的数据导出Excel 并计算某列的和。。该怎么实现呀!


数据已经导出了,可是还需要实现统计功能,比如统计 E F G的和。该怎么实现呀。
导出代码在下面
HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.Buffer = true;
        HttpContext.Current.Response.Charset = "UTF-8";
        //
        HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString("yyyy-mm-dd") + ".xls");
        HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
        HttpContext.Current.Response.ContentType = "application/ms-excel";

        //
        CultureInfo cultureInfo = new CultureInfo("ZH-CN", true);
        StringWriter stringWriter = new StringWriter(cultureInfo);
        HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
        this.Repeater1.RenderControl(htmlTextWriter);
        HttpContext.Current.Response.Write(stringWriter.ToString());           
        HttpContext.Current.Response.End();
C#,.net --------------------编程问答--------------------
引用 楼主 u012951068 的回复:

数据已经导出了,可是还需要实现统计功能,比如统计 E F G的和。该怎么实现呀。
导出代码在下面
HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.Buffer = true;
        HttpContext.Current.Response.Charset = "UTF-8";
        //
        HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString("yyyy-mm-dd") + ".xls");
        HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
        HttpContext.Current.Response.ContentType = "application/ms-excel";

        //
        CultureInfo cultureInfo = new CultureInfo("ZH-CN", true);
        StringWriter stringWriter = new StringWriter(cultureInfo);
        HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
        this.Repeater1.RenderControl(htmlTextWriter);
        HttpContext.Current.Response.Write(stringWriter.ToString());           
        HttpContext.Current.Response.End();


在导出前就应该统计好!然后导入进去! --------------------编程问答--------------------
Quote: 引用 1 楼 hou306010849 的回复:

Quote: 引用 楼主 u012951068 的回复:

在SQL里面统计么 --------------------编程问答--------------------
引用 2 楼 u012951068 的回复:
Quote: 引用 1 楼 hou306010849 的回复:

Quote: 引用 楼主 u012951068 的回复:

在SQL里面统计么


你的数据源怎么来的?

你导出到XLS 怎么排班的?

你可以在最后加入一行统计!

单独在后台统计出来,然后插入到最后一行! --------------------编程问答--------------------
引用 3 楼 hou306010849 的回复:
Quote: 引用 2 楼 u012951068 的回复:

Quote: 引用 1 楼 hou306010849 的回复:

Quote: 引用 楼主 u012951068 的回复:

在SQL里面统计么


你的数据源怎么来的?

你导出到XLS 怎么排班的?

你可以在最后加入一行统计!

单独在后台统计出来,然后插入到最后一行!

数据源就是一个DataTable。然后绑定到repeater的 --------------------编程问答--------------------
引用 4 楼 u012951068 的回复:
Quote: 引用 3 楼 hou306010849 的回复:

Quote: 引用 2 楼 u012951068 的回复:

Quote: 引用 1 楼 hou306010849 的回复:

Quote: 引用 楼主 u012951068 的回复:

在SQL里面统计么


你的数据源怎么来的?

你导出到XLS 怎么排班的?

你可以在最后加入一行统计!

单独在后台统计出来,然后插入到最后一行!

数据源就是一个DataTable。然后绑定到repeater的


怎么把你数据插入的??? --------------------编程问答--------------------
Quote: 引用 5 楼 hou306010849 的回复:

你是指插入EXCEL还是什么  我没明白 --------------------编程问答--------------------
引用 6 楼 u012951068 的回复:
Quote: 引用 5 楼 hou306010849 的回复:

你是指插入EXCEL还是什么  我没明白


插入XLS里面的数据,你是怎么插入的? --------------------编程问答--------------------
引用 7 楼 hou306010849 的回复:
Quote: 引用 6 楼 u012951068 的回复:

Quote: 引用 5 楼 hou306010849 的回复:

你是指插入EXCEL还是什么  我没明白


插入XLS里面的数据,你是怎么插入的?
HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.Buffer = true;
        HttpContext.Current.Response.Charset = "UTF-8";
        //
        HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString("yyyy-mm-dd") + ".xls");
        HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
        HttpContext.Current.Response.ContentType = "application/ms-excel";
 
        //
        CultureInfo cultureInfo = new CultureInfo("ZH-CN", true);
        StringWriter stringWriter = new StringWriter(cultureInfo);
        HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
        this.Repeater1.RenderControl(htmlTextWriter);
        HttpContext.Current.Response.Write(stringWriter.ToString());           
        HttpContext.Current.Response.End();
--------------------编程问答--------------------
引用 8 楼 u012951068 的回复:
Quote: 引用 7 楼 hou306010849 的回复:

Quote: 引用 6 楼 u012951068 的回复:

Quote: 引用 5 楼 hou306010849 的回复:

你是指插入EXCEL还是什么  我没明白


插入XLS里面的数据,你是怎么插入的?
HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.Buffer = true;
        HttpContext.Current.Response.Charset = "UTF-8";
        //
        HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString("yyyy-mm-dd") + ".xls");
        HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
        HttpContext.Current.Response.ContentType = "application/ms-excel";
 
        //
        CultureInfo cultureInfo = new CultureInfo("ZH-CN", true);
        StringWriter stringWriter = new StringWriter(cultureInfo);
        HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
        this.Repeater1.RenderControl(htmlTextWriter);
        HttpContext.Current.Response.Write(stringWriter.ToString());           
        HttpContext.Current.Response.End();


看看这个把!

http://www.cnblogs.com/qfb620/archive/2009/12/01/1614359.html

人家有指定列的,这样,你就可以把你数据加入到最后一行 统计了! --------------------编程问答-------------------- 这类,正常都是直接先程序统计后,再导出到Excel的,别想用程序去控制Excel一些宏计算功能。
简单事情应该简单做,别用复杂思维去做。 --------------------编程问答-------------------- 三种方式

1. 在SQL语句里就把合计统计出来

2. 在转Excel时,遍历repeater统计合计

3. 在Excel之后,调用Excel本身的宏去统计合计

最后一种最好。 --------------------编程问答-------------------- 量不大的话,直接在datatable里操作完成 --------------------编程问答-------------------- 如果我做的话,我的思路是:
  在前台不要repeater代码,直接定义一个div,在后台动态写一个datatable字符串,循环数据源,然后把需要统计的列统计出来,插入到最后一行。最后直接让div的内容等于这个字符串。导出时候数据都有了。
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,