c# html 导出excel
[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的更多相关文章
- C#使用Aspose.Cells导出Excel简单实现
首先,需要添加引用Aspose.Cells.dll,官网下载地址:http://downloads.aspose.com/cells/net 将DataTable导出Xlsx格式的文件下载(网页输出) ...
- 利用poi导出Excel
import java.lang.reflect.Field;import java.lang.reflect.InvocationTargetException;import java.lang.r ...
- [django]数据导出excel升级强化版(很强大!)
不多说了,原理采用xlwt导出excel文件,所谓的强化版指的是实现在网页上选择一定条件导出对应的数据 之前我的博文出过这类文章,但只是实现导出数据,这次左思右想,再加上网上的搜索,终于找出方法实现条 ...
- NPOI导出Excel
using System;using System.Collections.Generic;using System.Linq;using System.Text;#region NPOIusing ...
- ASP.NET Core 导入导出Excel xlsx 文件
ASP.NET Core 使用EPPlus.Core导入导出Excel xlsx 文件,EPPlus.Core支持Excel 2007/2010 xlsx文件导入导出,可以运行在Windows, Li ...
- asp.net DataTable导出Excel 自定义列名
1.添加引用NPOI.dll 2.cs文件头部添加 using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using System.IO; 3.代码如 ...
- Aspose.Cells导出Excel(1)
利用Aspose.Cells导出excel 注意的问题 1.DataTable的处理 2.进行编码,便于中文名文件下载 3.别忘了Aspose.Cells.dll(可以自己在网上搜索) public ...
- 前端导出Excel兼容写法
今天整理出在Web前端导出Excel的写法,写了一个工具类,对各个浏览器进行了兼容. 首先,导出的数据来源可能有两种: 1. 页面的HTML内容(一般是table) 2. 纯数据 PS:不同的数据源, ...
- JS导出excel 兼容ie、chrome、firefox
运用js实现将页面中的table导出为excel文件,页面显示如下: 导出的excel文件显示如下: 实现代码: <!DOCTYPE html> <html> <head ...
- Oracle导出excel
oracle导出excel(非csv)的方法有两种,1.使用sqlplus spool,2.使用包体 现将网上相关代码整理后贴出以备不时之需: 使用sqlplus: 使用sqlplus需要两个文件: ...
随机推荐
- 1.Redis介绍以及安装
Redis介绍 Redis是一个开源的(BSD开源协议),内存数据结构存储,被用于作为数据库,缓存和消息代理. Redis支持如下数据结构: string(字符串) hashes(哈希) lists ...
- #leetcode刷题之路35-搜索插入位置
给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引.如果目标值不存在于数组中,返回它将会被按顺序插入的位置.你可以假设数组中无重复元素. 示例 1:输入: [1,3,5,6], 5输出: ...
- ABAP术语-R/3 Repository Information System
R/3 Repository Information System 原文:http://www.cnblogs.com/qiangsheng/archive/2008/03/11/1100076.ht ...
- npm常见配置收集
npm代理设置为走ss通道:npm config set proxy 'http://localhost:1080'
- 解决 ajax 跨域
用两个服务器处理一个项目的代码,其中一台服务器只处理接口请求. 本来PHP可以使用CURL来处理,但是领导不允许使用PHP来处理数据.会影响网站的功能.如果接口端出现问题会导致整个网站或其页面的崩溃, ...
- Quote Helper
using System; using Microsoft.Xrm.Sdk; using Microsoft.Crm.Sdk.Messages; using Microsoft.Xrm.Sdk.Que ...
- MQTT的学习之Mosquitto安装&使用(1)
Mosquitto是一个实现了MQTT3.1协议的代理服务器,由MQTT协议创始人之一的Andy Stanford-Clark开发,它为我们提供了非常棒的轻量级数据交换的解决方案.本文的主旨在于记录M ...
- Redis在Linux中的运用
Redis在Linux中的运用 一.Redis安装部署 下载: wget http://download.redis.io/releases/redis-3.2.12.tar.gz 解压: 上传至 / ...
- Go语言入门(一)特性、安装、环境搭建、第一个程序等
Go语言是谷歌推出的一种全新的编程语言,可以在不损失应用程序性能的情况下降低代码的复杂性.谷歌首席软件工程师罗布派克(Rob Pike)说:我们之所以开发Go,是因为过去10多年间软件开发的难度令人沮 ...
- 厦门Uber优步司机奖励政策(12月28日到1月3日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...