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需要两个文件: ...
随机推荐
- oracle系列(二)用户管理
SQL> conn /as sysdbaConnected to Oracle Database 11g Express Edition Release 11.2.0.2.0 Connected ...
- 记一次简单的UITableView卡顿优化
先说需求,要做一个类似这种的列表 标签控件直接用的第三方 YZTagList 不知道的可以去搜一下,当这不重要. 重要的是这个控件加载数据的时候非常影响列表滑动效果,造成卡顿,尤其是列表行数如果更多的 ...
- 网站程序application, session, cookie区别的一点小总结
cookie:是存放于本地的文件,可以设置期限,一般来讲是比较小文本或键值对等,主要用于记录用户浏览信息,账号密码等等.可以让人们的登录变得方便,因为有了cookie,在一段时间内就可以自动登录以前所 ...
- #leetcode刷题之路15-三数之和
给定一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?找出所有满足条件且不重复的三元组. 注意:答案中不可以包含重复的三元组. ...
- 使用 jTessBoxEditor 生成 tesseract-orc 的字典
本文使用图片方式记录使用 jTessBoxEditor 一站式生成自动文件的方式 首先感谢 Tesseract OCR 讨论群 389402579 的管理员[创世倾城 QQ:457606663] 的帮 ...
- Flask入门数据库的查询集与过滤器(十一)
1 查询集 : 指数据查询的集合 原始查询集: 不经过任何过滤返回的结果为原始查询集 数据查询集: 将原始查询集经过条件的筛选最终返回的结果 查询过滤器: 过滤器 功能 cls.query.filte ...
- dubbo配置注意
API接口的路径在provider和consumer端的路径要一致
- angularjs脏机制
Angular 每一个绑定到UI的数据,就会有一个 $watch 对象. watch = { name:'', //当前的watch 对象 观测的数据名 getNewValue:function($s ...
- 微信小程序快速转成百度小程序的方法
1.安装Node.js(>8.5.0)https://nodejs.org/ npm升级到最新版本的方法:npm install -g npm自动更新到最新版本 2.配置cnpm:在命令行中输入 ...
- SQLite学习笔记
参考书籍 <SQLite 权威指南 第二版> Windows获取SQLite 1.主页: www.sqlite.org 2.下载 Precompiled Binaries For Wind ...