asp.net MVC 文件流导出Excel
<form id="FormEsExcel" action="/**/ExportEsExcelData" method="post"> </form>
<div style="float: right; margin-top: 25px; margin-bottom: 5px;">
<a class="btn120" href="#" onclick="ShowExportData()">导出</a>
</div>
public FileResult ExportEsExcelData()
{ var sbHtml = new StringBuilder();
sbHtml.Append("<table border='1' cellspacing='0' cellpadding='0'>");
sbHtml.Append("<tr>");
var lstTitle = new List<string> { "序列号1", "序列号1", "序列号1", "序列号1", "序列号1", "序列号1", "序列号1", "序列号1", "序列号1", "序列号1", "序列号1", "序列号1", "序列号1", "序列号1", "序列号1", "序列号1", "序列号1", "序列号1", "序列号1", "序列号1","序列号1" };
foreach (var item in lstTitle)
{
sbHtml.AppendFormat("<td style='font-size: 14px;text-align:center;background-color: #DCE0E2; font-weight:bold;' height='25'>{0}</td>", item);
}
sbHtml.Append("</tr>");
try
{
ExportParamDTO param = new ExportParamDTO();
string orderIs = SessionHelper.Get("orderids");
List<Guid> orderlist = new List<Guid>();
if (orderIs!=null)
{
string[] arr = orderIs.Split(',').ToArray();
foreach (var item in arr)
{
orderlist.Add(Guid.Parse(item));
}
}
param._orderIds = orderlist;
CommodityOrderFacade orderBP = new CommodityOrderFacade();
List<ExportResultDTO> result = orderBP.ExportResult(param);
int i = , orderItemCount = , j = ;
foreach (ExportResultDTO model in result)
{
orderItemCount = model.Products == null ? : model.Products.Count;
j = ;
foreach (ProductList product in model.Products)
{
if (model.State == || model.StateAfterSales == )
{
model.ChannelShareMoney = ;
}
sbHtml.Append("<tr>");
if (orderItemCount > && j == )
{
sbHtml.AppendFormat("<td rowspan='{0}' style='font-size: 12px;height:20px;'>{1}</td>", orderItemCount, i);
sbHtml.AppendFormat("<td rowspan='{0}' style='font-size: 12px;height:20px;vnd.ms-excel.numberformat:@'>{1}</td>", orderItemCount, model.Code);
}
else if (orderItemCount == )
{
sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;'>{0}</td>", i);
sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;vnd.ms-excel.numberformat:@'>{0}</td>", model.Code);
}
sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;vnd.ms-excel.numberformat:@'>{0}</td>", model.AppName);
sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;vnd.ms-excel.numberformat:@'>{0}</td>", model.AppType);
sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;vnd.ms-excel.numberformat:@'>{0}</td>", product.ProductName);
sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;'>{0}</td>", product.ProductPric);
sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;'>{0}</td>", product.BuyNumber);
if (orderItemCount > && j == )
{
sbHtml.AppendFormat("<td rowspan='{0}' style='font-size: 12px;height:20px;'>{1}</td>", orderItemCount, model.OrdersTime);
sbHtml.AppendFormat("<td rowspan='{0}' style='font-size: 12px;height:20px;'>{1}</td>", orderItemCount, model.PaymentTime);
sbHtml.AppendFormat("<td rowspan='{0}' style='font-size: 12px;height:20px;'>{1}</td>", orderItemCount, model.PaymentType);
sbHtml.AppendFormat("<td rowspan='{0}' style='font-size: 12px;height:20px;'>{1}</td>", orderItemCount, model.PracticalPayment);
sbHtml.AppendFormat("<td rowspan='{0}' style='font-size: 12px;height:20px;vnd.ms-excel.numberformat:@'>{1}</td>", orderItemCount, GetOrderStateDescription(model.State, model.SelfTakeFlag, model.StateAfterSales));
if (model.State == && model.RefundMoney + model.RefundScoreMoney >= )
{
if (model.RefundScoreMoney > )
{
sbHtml.AppendFormat("<td rowspan='{0}' style='font-size: 12px;height:20px;'>{1}(含{2}元积分)</td>", orderItemCount, model.RefundMoney.Value + model.RefundScoreMoney, model.RefundScoreMoney);
}
else
{
sbHtml.AppendFormat("<td rowspan='{0}' style='font-size: 12px;height:20px;'>{1}</td>", orderItemCount, model.RefundMoney.Value);
}
}
else
{
sbHtml.AppendFormat("<td rowspan='{0}' style='font-size: 12px;height:20px;'>{1}</td>", orderItemCount, "");
}
sbHtml.AppendFormat("<td rowspan='{0}' style='font-size: 12px;height:20px;vnd.ms-excel.numberformat:@'>{1}</td>", orderItemCount, model.Payer);
sbHtml.AppendFormat("<td rowspan='{0}' style='font-size: 12px;height:20px;vnd.ms-excel.numberformat:@'>{1}</td>", orderItemCount, model.Phone);
sbHtml.AppendFormat("<td rowspan='{0}' style='font-size: 12px;height:20px;vnd.ms-excel.numberformat:@'>{1}</td>", orderItemCount, model.ShippingAddress);
sbHtml.AppendFormat("<td rowspan='{0}' style='font-size: 12px;height:20px;'>{1}</td>", orderItemCount, model.Freight);
sbHtml.AppendFormat("<td rowspan='{0}' style='font-size: 12px;height:20px;'>{1}</td>", orderItemCount, model.GoldCoupon);
sbHtml.AppendFormat("<td rowspan='{0}' style='font-size: 12px;height:20px;'>{1}</td>", orderItemCount, model.CouponValue);
sbHtml.AppendFormat("<td rowspan='{0}' style='font-size: 12px;height:20px;'>{1}</td>", orderItemCount, model.JczfAmonut);
sbHtml.AppendFormat("<td rowspan='{0}' style='font-size: 12px;height:20px;vnd.ms-excel.numberformat:@'>{1}</td>", orderItemCount, model.SpendYJBMoney); }
else if (orderItemCount == )
{
sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;'>{0}</td>", model.OrdersTime);
sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;'>{0}</td>", model.PaymentTime);
sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;vnd.ms-excel.numberformat:@'>{0}</td>", model.PaymentType);
sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;'>{0}</td>", model.PracticalPayment);
sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;vnd.ms-excel.numberformat:@'>{0}</td>", GetOrderStateDescription(model.State, model.SelfTakeFlag, model.StateAfterSales));
if (model.State == && model.RefundMoney >= || model.State == && model.StateAfterSales == && model.RefundMoney >= )
{
if (model.RefundScoreMoney > )
{
sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;'>{0}(含{1}元积分)</td>", model.RefundMoney.Value + model.RefundScoreMoney, model.RefundScoreMoney);
}
else
{
sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;'>{0}</td>", model.RefundMoney.Value);
}
}
else
{
sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;'>{0}</td>", "");
}
sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;vnd.ms-excel.numberformat:@'>{0}</td>", model.Payer);
sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;vnd.ms-excel.numberformat:@'>{0}</td>", model.Phone);
sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;vnd.ms-excel.numberformat:@'>{0}</td>", model.ShippingAddress);
sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;'>{0}</td>", model.Freight);
sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;'>{0}</td>", model.GoldCoupon);
sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;'>{0}</td>", model.CouponValue);
// sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;'>{0}</td>", model.SpendYJBMoney);
sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;'>{0}</td>", model.JczfAmonut); sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;vnd.ms-excel.numberformat:@'>{0}</td>", model.SpendYJBMoney); }
sbHtml.Append("</tr>"); j++;
}
i++;
}
}
catch (Exception ex)
{ }
sbHtml.Append("</table>");
return File(System.Text.Encoding.UTF8.GetBytes(sbHtml.ToString()), "application/ms-excel", string.Format("dingdan{0}.xls", DateTime.Now.ToString("yyyyMMddHHmmss")));
}
asp.net MVC 文件流导出Excel的更多相关文章
- Asp.Net MVC 使用FileResult导出Excel数据文件
MVC实现Excel导出功能,今天来记录一下. 采取了最简单的方法.(转载) 用的是Html拼接成Table表格的方式,返回 FileResult 输出一个二进制的文件. 第一种:使用FileCo ...
- asp.net Mvc 使用NPOI导出Excel文件
1.新建MVC项目,新建控制器.视图 添加控制器: 添加视图(将使用布局页前面的复选框里的勾勾去掉) 2.在Models里新建一个类 public class Shop { /// <summa ...
- ASP.NET MVC 使用NPOI导出Excel 无法访问已关闭的流(转)
第一步重写MemoryStream , 让它不能自动关闭. //新建类 重写Npoi流方法 public class NpoiMemoryStream : MemoryStream { public ...
- 前端接收后端文件流导出excel文档遇到的问题
先上代码: Vue.prototype.download = function(oUrl, filename) { this.axios .get(oUrl, { responseType: 'arr ...
- vue 后台获取文件流导出excel文件
let params = { compStartTm: Date.parse(this.searchForm.compStartTm) / 1000, compEndTm: Date.parse(th ...
- asp.net以流导出Excel
废话不多说,直接上代码 这是点击导出的事件函数,因为我是从前端获取的Table的json数据,所以需要转换一下,大家直接用查询出来的DataTable即可 protected void bt_expo ...
- ASP.NET MVC 文件上传和路径处理
ASP.NET MVC 文件上传和路径处理总结 目录 文件的上传和路径处理必须解决下面列出的实际问题: 1.重复文件处理 2.单独文件上传 3.编辑器中文件上传 4.处理文章中的图片路径 5.处理上传 ...
- ASP.NET MVC文件上传【转】
最近用到了文件上传功能,下面给出ASP.NET MVC文件上传的一个简单示例: 一.前端代码 @using (Html.BeginForm("UploadFile", " ...
- MVC NPOI Linq导出Excel通用类
之前写了一个模型导出Excel通用类,但是在实际应用中,可能不是直接导出模型,而是通过Linq查询后获取到最终结果再导出 通用类: public enum DataTypeEnum { Int = , ...
随机推荐
- Ajax异步请求阻塞情况的解决办法
最近使用ExtJs4的mvc模式在开发了在线漫画的后台,因为异步请求比较多,有的回应时间长,有点短.我发现在多次并发的情况下,会造成阻塞的情况.也就是说如果回应时间长的请求还在进行中,短的请求却被挂起 ...
- RabbitMQ 消息队列 DEMO
1. 引用 RabbitMQ.Client.5.1.0 2. http://localhost:15672/ public class TestController : ApiController { ...
- BlangenOA项目总结
1.使用EF,当返回的是IQueryable<T>类型,延迟加载. 2.增删改查 分页(页码,页大小,总记录数,是否升序)(两个lambda表达式,一个筛选规则,一个是排序规则(可以选择类 ...
- .net core grpc consul 实现服务注册 服务发现 负载均衡(二)
在上一篇 .net core grpc 实现通信(一) 中,我们实现的grpc通信在.net core中的可行性,但要在微服务中真正使用,还缺少 服务注册,服务发现及负载均衡等,本篇我们将在 .net ...
- .Net Core与跨平台时区
由于开发者不熟悉不同操作系统管理时区的方式,当用.Net Core开发与时区相关的应用运行在不同操作系统上会出现错误.这片文章将会探索一下在不同操作系统上用.Net Core 使用时区信息出现的问题与 ...
- ACTGame项目
项目地址:https://github.com/alonecat06/ACTGame游戏地址:http://pan.baidu.com/s/1hqD3IYw 项目是一个自制单机动作游戏demo,方向是 ...
- 【cocos2d-x 3.0-Mac配置篇】
就在昨天触控正式发布了3.0正式版本... 在这个喜大普奔的日子里,我们又开始了新一轮的革命,先不说其他的,再来看看3.0目录文件里面有什么? 首先是精简了很多,无论是从目录结构,和所用到的工具类,都 ...
- day 69 ORM 多表增删改查操作
http://www.cnblogs.com/liwenzhou/p/8660826.html 下面的代码是在 python console中配置的. 关闭pycharm会消失. from app01 ...
- JAVA 定时器时间格式
格式: [秒] [分] [小时] [日] [月] [周] [年] 通配符说明: \*:表示所有值.例如:在分的字段上设置"\*",表示每一分钟都会触发. ?:表示不指定值.使用的场 ...
- Android------------fragment数据传递
一.activity向fragment的数值之间的传递 关键点:fragment.setArguments(bundle);---->activity发出的信息 Bundle bund ...