[CustomAuthorize]
        public FileResult ExportCustomerManagerVisitExcel(string dateType, string realVisitDate, string isRenew)
        {
            string dateFormat = "yyyy-MM-dd";
            switch (dateType)
            {
                case "0": dateFormat = "yyyy-MM-dd"; break;
                case "1": dateFormat = "yyyy-MM"; break;
                case "2": dateFormat = "yyyy"; break;
                default: dateFormat = "yyyy-MM-dd"; break;
            }

IList<CustomerManagerVisitStatistics> listTotal = orderitemManager.GetCustomerManagerVisitStatistics(dateFormat, realVisitDate, isRenew);

StringWriter strWriter = new StringWriter();
            HtmlTextWriter htmlWriter = new HtmlTextWriter(strWriter);

if (listTotal.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
                sb.Append("<thead>");
                sb.Append("<tr>");
                sb.Append("<th>组名</th>");
                sb.Append("<th>姓名</th>");
                sb.Append("<th>日期</th>");
                sb.Append("<th>回访总数</th>");
                sb.Append("<th>意向客户总数</th>");
                sb.Append("<th>意向客户占比(%)</th>");
                sb.Append("<th>小组回访总数</th>");
                sb.Append("<th>小组意向客户总数</th>");
                sb.Append("<th>小组平均值(%)</th>");
                sb.Append("</tr>");
                sb.Append("</thead>");
                sb.Append("<tbody>");

string html = "";
                string groupFirstRow = "";
                string groupOtherRow = "";
                string displayGroupName = "";
                string groupName = "";
                int groupRowspan = 0;
                int groupVisitCount = 0;
                int groupIntentionCount = 0;

foreach (CustomerManagerVisitStatistics item in listTotal)
                {
                    if (item.ParentId == "0")
                    {
                        if (groupRowspan > 0 && groupFirstRow != "")
                        {
                            groupFirstRow = "<tr><td rowspan='" + groupRowspan.ToString() + "'>" + displayGroupName + "</td>" + groupFirstRow + "<td rowspan='" + groupRowspan.ToString() + "'>" + groupVisitCount
                            + "</td><td rowspan='" + groupRowspan.ToString() + "'>" + groupIntentionCount + "</td><td rowspan='" + groupRowspan.ToString() + "'>";
                            if (groupVisitCount == 0)
                            {
                                groupFirstRow = groupFirstRow + "0</td></tr>";
                            }
                            else
                            {
                                groupFirstRow = groupFirstRow + Math.Round(decimal.Parse(((decimal)groupIntentionCount / groupVisitCount * 100).ToString()), 2).ToString() + "</td></tr>";
                            }

html = html + groupFirstRow + groupOtherRow;
                        }
                        groupName = item.GroupName;
                        displayGroupName = item.GroupName + "(" + item.CustomerManagerName + ")";
                        groupRowspan = 0;
                        groupVisitCount = 0;
                        groupIntentionCount = 0;
                        groupFirstRow = "";
                        groupOtherRow = "";
                    }
                    else
                    {
                        groupRowspan = groupRowspan + 1;
                        groupVisitCount = groupVisitCount + item.VisitCount;
                        groupIntentionCount = groupIntentionCount + item.IntentionCount;

if (groupRowspan == 1)
                        {
                            groupFirstRow = "<td>" + item.CustomerManagerName + "</td>" + "<td>" + item.RealVisitDate + "</td>" + "<td>" + item.VisitCount + "</td>" + "<td>" + item.IntentionCount + "<td>" + item.IntentionRate + "</td>";
                        }
                        else
                        {
                            groupOtherRow = groupOtherRow + "<tr><td>" + item.CustomerManagerName + "</td>" + "<td>" + item.RealVisitDate + "</td>" + "<td>" + item.VisitCount + "</td>" + "<td>" + item.IntentionCount + "<td>" + item.IntentionRate + "</td></tr>";
                        }

}

}

if (groupRowspan > 0 && groupFirstRow != "")
                {
                    groupFirstRow = "<tr><td rowspan='" + groupRowspan.ToString() + "'>" + displayGroupName + "</td>" + groupFirstRow + "<td rowspan='" + groupRowspan.ToString() + "'>" + groupVisitCount
                            + "</td><td rowspan='" + groupRowspan.ToString() + "'>" + groupIntentionCount + "</td><td rowspan='" + groupRowspan.ToString() + "'>";
                    if (groupVisitCount == 0)
                    {
                        groupFirstRow = groupFirstRow + "0</td></tr>";
                    }
                    else
                    {
                        groupFirstRow = groupFirstRow + Math.Round(decimal.Parse(((decimal)groupIntentionCount / groupVisitCount * 100).ToString()), 2).ToString() + "</td></tr>";
                    }

html = html + groupFirstRow + groupOtherRow;
                }

sb.Append(html);
                sb.Append("</tbody>");
                sb.Append("</table>");

strWriter.Write(sb.ToString());
            }
            else
            {
                strWriter.WriteLine("没有数据!");
            }

byte[] fileContents = Encoding.GetEncoding("gb2312").GetBytes("<html><head><meta http-equiv=Content-Type content=\"text/html; charset=gb2312\">" + strWriter.ToString() + "</body></html>");
            return File(fileContents, "application/vnd.ms-excel", string.Format("{0}.xls", "回访统计汇总" + DateTime.Now.Date.ToString("yyyyMMdd")));
        }

c# html 导出excel的更多相关文章

  1. C#使用Aspose.Cells导出Excel简单实现

    首先,需要添加引用Aspose.Cells.dll,官网下载地址:http://downloads.aspose.com/cells/net 将DataTable导出Xlsx格式的文件下载(网页输出) ...

  2. 利用poi导出Excel

    import java.lang.reflect.Field;import java.lang.reflect.InvocationTargetException;import java.lang.r ...

  3. [django]数据导出excel升级强化版(很强大!)

    不多说了,原理采用xlwt导出excel文件,所谓的强化版指的是实现在网页上选择一定条件导出对应的数据 之前我的博文出过这类文章,但只是实现导出数据,这次左思右想,再加上网上的搜索,终于找出方法实现条 ...

  4. NPOI导出Excel

    using System;using System.Collections.Generic;using System.Linq;using System.Text;#region NPOIusing ...

  5. ASP.NET Core 导入导出Excel xlsx 文件

    ASP.NET Core 使用EPPlus.Core导入导出Excel xlsx 文件,EPPlus.Core支持Excel 2007/2010 xlsx文件导入导出,可以运行在Windows, Li ...

  6. asp.net DataTable导出Excel 自定义列名

    1.添加引用NPOI.dll 2.cs文件头部添加 using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using System.IO; 3.代码如 ...

  7. Aspose.Cells导出Excel(1)

    利用Aspose.Cells导出excel 注意的问题 1.DataTable的处理 2.进行编码,便于中文名文件下载 3.别忘了Aspose.Cells.dll(可以自己在网上搜索) public ...

  8. 前端导出Excel兼容写法

    今天整理出在Web前端导出Excel的写法,写了一个工具类,对各个浏览器进行了兼容. 首先,导出的数据来源可能有两种: 1. 页面的HTML内容(一般是table) 2. 纯数据 PS:不同的数据源, ...

  9. JS导出excel 兼容ie、chrome、firefox

    运用js实现将页面中的table导出为excel文件,页面显示如下: 导出的excel文件显示如下: 实现代码: <!DOCTYPE html> <html> <head ...

  10. Oracle导出excel

    oracle导出excel(非csv)的方法有两种,1.使用sqlplus  spool,2.使用包体 现将网上相关代码整理后贴出以备不时之需: 使用sqlplus: 使用sqlplus需要两个文件: ...

随机推荐

  1. Linux中文件函数(二)

    一.link.linkat.unlink.unlinkat.remove函数 创建一个指向现有文件的链接的方法是使用link函数或linkat函数.函数的原型为: #include <unist ...

  2. 学生管理系统增删查基本操作(dom4j/sax技术)

    基本代码: student.xml <?xml version="1.0" encoding="UTF-8"?><student> &l ...

  3. 使用Hbuilder开发IOS应用上架审核提示请指定用户在位置许可模式警报中使用位置的预定用途。

    使用Hbuilder开发IOS应用时,遇到上架App被拒的问题,被拒原因: 你的应用程序使用位置服务,但并没有按照iOS人机界面指南中的要求,在位置模式警报中阐明它的用途. 要解决此问题,请指定用户在 ...

  4. 一台ECS服务器,部署多(两)应用,且应用配置不同域名

    场景 产品环境服务器有两台,前后端各分配一台服务器.现在在不增加机器的情况下,需要增加部署一套服务给台北地区服务. 现有的前端部署方案. 产品环境部署方案详解 实现 配置NAT步骤 ECS配置多网卡, ...

  5. Git 学习笔记–基本操作

    Git 与 SVN 不同,是分布式的版本控制系统,不需要主服务器即可工作,实际中为了方便各个工作者间同步工作,通常还是会设置主服务器. Git的设置及初始化: 设置全局用户信息: luojiahu@u ...

  6. Opportunity Helper

    using System; using Microsoft.Xrm.Sdk; using Microsoft.Crm.Sdk.Messages; public class OpportunityHel ...

  7. linux运维视频教程

    视频教程:https://www.bilibili.com/video/av31023006/?p=2 1.文件系统 文件系统树形结构: 对于linux系统的user和application来说,并不 ...

  8. Scala学习笔记(四)—— 数组

    定长数组Array 定义定长数组用Array,有如下几种方法: 初始化一个长度为8的定长数组,其所有元素默认值均为0 scala> new Array[Int](8) res0: Array[I ...

  9. 【Hadoop】Seondary NameNode不是备份NameNode!!

    昨天和舍友聊天时无意中提起Secondary NameNode,他说这是备用NameNode.我当时就有点疑惑..之后查阅了相关资料和博客,算是基本理解了什么是Secondary NameNode. ...

  10. (转) 如何从 0 开始学 ruby on rails (漫步版)

    原文:http://readful.com/post/12322300571/0-ruby-on-rails ruby 是一门编程语言,ruby on rails 是 ruby 的一个 web 框架, ...