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 = , ...
随机推荐
- MVC-1.1 BundleConfig-ScriptBundle
App_Start中的BudleCnfig.cs中 bundles.Add(new ScriptBundle("~/bundles/jquery").Include( " ...
- LinkServer--访问远程数据表三种方式
在TSQL中访问远程数据库有三种方式:1.OPENROWSET2.OPENDATASOURCE3.LinkServer 在使用openrowset/opendatasource前搜先要启用Ad Hoc ...
- .Net Core 跨平台应用使用串口、串口通信 ,可能出现的问题、更简洁的实现方法
前些天在学习在 .NET Core下,跨平台使用串口通讯,有一篇文章说到在Linux/物联网下,实现通讯. 主要问题出现在以下两个类库 SerialPortStream flyfire.CustomS ...
- 【2019年OCP新题】OCP题库更新出现大量新题-11
11.Your database is in archivelog mode. You want to disable archiving for the database. Examine thes ...
- js中call、apply、bind的使用
写在前面的话 这三个方法都是来自Function.prototype上,所以所有的函数都可以使用. 他们有一个共同点,就是可以指定函数执行时的内部this指向. call和apply的区别在于参数的方 ...
- day 68crm(5) 分页器的进一步优化,以及在stark上使用分页器,,以及,整理代码,以及stark组件search查询
前情提要: 本节内容 自定制分页器 保存及查询记录 代码整理, stark组件search 查询 一:自定制分页器 page 1:创建类 Pagination # 自定制分页器 _ _init ...
- 云链接 接口不允许 情况 解决方法 mysql Host is not allowed to connect to this MySQL server解决方法
在装有MySQL的机器上登录MySQL mysql -u root -p密码 执行use mysql; 执行update user set host = '%' where user = 'root' ...
- 剑指offer三十七之数字在排序数组中出现的次数
一.题目 统计一个数字在排序数组中出现的次数. 二.思路 解法一:遍历数组计数 解法二:考虑到时有序数组,所以采用分查找,找到第一个K 和 最后一个K的位置, 二者相减. 三.代码 解法一: publ ...
- Spring Security构建Rest服务-0400-使用切片拦截rest服务
Restful API的拦截: 1,过滤器(Filter) 2,拦截器(Interceptor) 3,切片(Aspect) 1,过滤器 和传统javaweb一鸟样,例,记录controller执行时间 ...
- [webpack]path、publicPath、--content-base 理解
附源码:http://files.cnblogs.com/files/chenshao/startPublic.rar 'use strict'; var webpack = require('web ...