<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的更多相关文章

  1. Asp.Net MVC 使用FileResult导出Excel数据文件

    MVC实现Excel导出功能,今天来记录一下. 采取了最简单的方法.(转载)   用的是Html拼接成Table表格的方式,返回 FileResult 输出一个二进制的文件. 第一种:使用FileCo ...

  2. asp.net Mvc 使用NPOI导出Excel文件

    1.新建MVC项目,新建控制器.视图 添加控制器: 添加视图(将使用布局页前面的复选框里的勾勾去掉) 2.在Models里新建一个类 public class Shop { /// <summa ...

  3. ASP.NET MVC 使用NPOI导出Excel 无法访问已关闭的流(转)

    第一步重写MemoryStream , 让它不能自动关闭. //新建类 重写Npoi流方法 public class NpoiMemoryStream : MemoryStream { public ...

  4. 前端接收后端文件流导出excel文档遇到的问题

    先上代码: Vue.prototype.download = function(oUrl, filename) { this.axios .get(oUrl, { responseType: 'arr ...

  5. vue 后台获取文件流导出excel文件

    let params = { compStartTm: Date.parse(this.searchForm.compStartTm) / 1000, compEndTm: Date.parse(th ...

  6. asp.net以流导出Excel

    废话不多说,直接上代码 这是点击导出的事件函数,因为我是从前端获取的Table的json数据,所以需要转换一下,大家直接用查询出来的DataTable即可 protected void bt_expo ...

  7. ASP.NET MVC 文件上传和路径处理

    ASP.NET MVC 文件上传和路径处理总结 目录 文件的上传和路径处理必须解决下面列出的实际问题: 1.重复文件处理 2.单独文件上传 3.编辑器中文件上传 4.处理文章中的图片路径 5.处理上传 ...

  8. ASP.NET MVC文件上传【转】

    最近用到了文件上传功能,下面给出ASP.NET MVC文件上传的一个简单示例: 一.前端代码 @using (Html.BeginForm("UploadFile", " ...

  9. MVC NPOI Linq导出Excel通用类

    之前写了一个模型导出Excel通用类,但是在实际应用中,可能不是直接导出模型,而是通过Linq查询后获取到最终结果再导出 通用类: public enum DataTypeEnum { Int = , ...

随机推荐

  1. 设计模式之工厂模式(Factory Pattern)

    一.什么是工厂模式? 1.“简单工厂模式”,Simple Factory Pattern 也就是常用的在Factory类中定义静态方法负责new对象的方式. 摘要中提到过“严格地说,这种被称为“简单工 ...

  2. c# HashSet 列表去重

    List<, , , }; HashSet<int> hs = new HashSet<int>(list); List<, , , }; HashSet<i ...

  3. System.IO.FileLoadException:“混合模式程序集是针对“v2.0.50727”版的运行时生成的,在没有配置其他信息的情况下,无法在 4.0 运行时中加载该程序集。”

    解决方案: 在app.config新增如下配置节: <?xml version="1.0"?> <configuration> <startup us ...

  4. 用idea做springboot开发,设置thymeleaf时候,新手容易忽略误区

    最近小编因为工作原因需要完成工厂自动化改造,而思来想去觉得还是用Java开发,因为很久没有敲过代码,对java这块已经抛掉很多年.作为工厂自动开发或者大型企业级开发,个人认为java和C#会比较合适, ...

  5. 【cocos2d-x 仙凡奇缘-网游研发(1) 登录&注册】

    转载请注明出处:http://www.cnblogs.com/zisou/p/xianfan01.html 公司的项目总算告一段落了,年前憋到年后,总算要上线了,所以我也有了时间来搞我自己的游戏项目了 ...

  6. 国际化SEO优化的最佳实践

    作者:Kristopher Jones 翻译 :吴祺深 欢迎访问网易云社区,了解更多网易技术产品运营经验. 让我们来说一下hreflang属性.如果你还没有关掉这个页面,那么你已经完成了这个教程最重要 ...

  7. 741. Cherry Pickup

    In a N x N grid representing a field of cherries, each cell is one of three possible integers. 0 mea ...

  8. python 模块导入全局变量

    在哪种情况下需要从模块导入全局变量 项目里多个脚本均更改「某一个全局变量」时 全量变量需要实现可配置时 从模块导入全局变量的方法 from test_prokject import global_va ...

  9. hdoj1575 Tr A(矩阵快速幂)

    简单的矩阵快速幂.最后求矩阵的秩. #include<iostream> #include<cstring> using namespace std; ; int n,k; s ...

  10. 从 falcon api 中获取数据

    import json import time import requests openfalcon = 'http://ip:port/api/v1' user = 'user' password ...