<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. 我也谈谈.NET程序员工资低

    我从2011年下半年预谋转型,2012春季正式转型到iOS,看了<经过本人 6 年.net 工作经验证明 .net 工资确实比 Java 低>这篇文章,一下子有很多感慨. 我不好意思算我干 ...

  2. 如何使用linq读取DataTable集合?AsQueryable() 和 AsEnumerable()区别?

    一.准备工作 引入linq和data 相关的using命名空间 DataTable dt=new DataTable();//dt的来源可以是多个地方,比如:数据库,Excel等等.我这里使用Exce ...

  3. S11 day 96 RestFramework 之认证权限

    一.设计一个简易的登录 1. 建立一个模型 class UserInfo(models.Model): username =models.CharField(max_length=) password ...

  4. XCode - 无法对iPhone真机调试的解决方法!

    OSX:10.14 XCode:10.1 真机:iPhone 4S 错误很多啊,并非编译错误,编译已经成功了,但是无法安装到真机,我真不理解啊!!由于真的没有想到能够解决,有的错误没有截图,先看部分错 ...

  5. 1002. Find Common Characters

    Given an array A of strings made only from lowercase letters, return a list of all characters that s ...

  6. LOJ#3088. 「GXOI / GZOI2019」旧词(树剖+线段树)

    题面 传送门 题解 先考虑\(k=1\)的情况,我们可以离线处理,从小到大对于每一个\(i\),令\(1\)到\(i\)的路径上每个节点权值增加\(1\),然后对于所有\(x=i\)的询问查一下\(y ...

  7. git fetch and git pull &冲突

    1.git fetch和git pull之间的区别 git fetch只会将本地库所关联的远程库的commit id更新至最新,fetch不会改变代码,如果想使代码更新,需要使用git merge o ...

  8. JavaScript定时器作业

    JavaScript定时器作业 <!DOCTYPE html> <html lang="zh-CN"> <head> <meta char ...

  9. robot framework 测试/预发/线上环境快捷切换

    通常情况下布署的三套环境:测试.预发及线上环境.调试或者辅助验证测试时,切环境改变量甚是麻烦.这些变量包括但不限于:一些url信息,数据库信息,预置用户信息等. 切换环境方法一:使用变量文件,通过判断 ...

  10. falcon nodata 小坑一枚

    按照官方文档配置完一切正常,唯独 nodata, 明明有正常的数据,但是为什么 nodata 会认为是没收到呢 困扰许久,直到看了数据库中的数据才恍然大悟 falcon_portal库中的 hosts ...