.net layui 批量导出
.net开发,前台使用layui框架,后台使用WCF
废话不多,直接上代码
1>文件引用:
admin.css
layui.css
layui.js
jquery.min.js
layerTool.js
2>前台:
<script type="text/html" id="toptoolbar">
<button class="layui-btn layui-btn-sm" lay-event="ExportExcel">批量导出</button>
</script>
----------先来个批量导出的按钮 (ExportExcel)自定义
layui.use(['table', 'form', 'util'], function () {
var form = layui.form, layer = layui.layer;
var table = layui.table;
var field = null;
var util = layui.util;
table.on('toolbar(ListSupplierTable)', function (obj) {
switch (obj.event) {
case 'ExportExcel'://批量导出
ShowExportExcelWin();
break;
};
});
});
----------('table', 'form', 'util')看需求增减
----------(var form = layui.form, layer = layui.layer; var table = layui.table; var field = null; var util = layui.util;) 看需求增减
----------ShowExportExcelWin //方法名
//打开批量导出弹窗
var exportOpen;
function ShowExportExcelWin() {
var $ = layui.jquery;
var html = '<div class="layui-form">';
html += ' <div class="layui-form-item">';
html += ' <div class="layui-input-inline" style="padding-left:55px;padding-top:20px;">';
html += ' <input type="radio" name="rdowhere" value="1" title="全部导出" checked><br />';
html += ' <input type="radio" name="rdowhere" value="2" title="按筛选条件导出" >';
html += ' </div>';
html += ' </div>';
html += '</div>';
exportOpen = layer.open({
type: ,
title: '批量导出',
area: ['300px', '210px'],//宽高
btn: ['导出'],
yes: function () {
var FullName = $('#FullName').val();//供应商全称(筛选条件)
var SupplierType = $('#SupplierType').val();//供应商类型(筛选条件)
var SupplierLevel = $('#SupplierLevel').val();//供应商级别(筛选条件)
var LabMallSupplierIsEnable = $('#LabMallSupplierIsEnable').val();//是否启用(筛选条件)
var GoodsHomeShow = $('#GoodsHomeShow').val();//是否显示Log(筛选条件) var ExportType = $("input[name='rdowhere']:checked").val();//导出类型(1:全部;2:筛选) layer.load(, { shade: [0.1, '#000'] });//上传loading $.post("ExportExcelToSupplier", { FullName: FullName, SupplierType: SupplierType, SupplierLevel: SupplierLevel, LabMallSupplierIsEnable: LabMallSupplierIsEnable, GoodsHomeShow: GoodsHomeShow, ExportType: ExportType }, function (res) {
layer.closeAll('loading');//关闭loading
if (res.success) {
layer.close(exportOpen);
layer.msg("导出成功");
location.href = res.payload;
} else {
layer.alert(res.error.message, { title: '导出失败' });
}
}, "json");
},
content: html
});
layui.form.render();
}
----------导出功能分为全部导出和按照筛选条件导出
----------ExportExcelToSupplier //接口名
3>接口:
#region 批量导出供应商
/// <summary>
/// 批量导出供应商
/// </summary>
/// <returns></returns>
public JsonResult ExportExcelToSupplier()
{
LabMallSupplierEntity supplier = new LabMallSupplierEntity();
supplier.LabMallSupplierIsEnable = -;
supplier.LabMallSupplierIsDelete = -; int ExportType = GetRequestInt("ExportType");
if (ExportType == )
{
supplier.FullName = GetRequestString("FullName");
supplier.SupplierType = GetRequestInt("SupplierType");
supplier.SupplierLevel = GetRequestInt("SupplierLevel");
supplier.LabMallSupplierIsEnable = GetRequestInt("LabMallSupplierIsEnable");
supplier.GoodsHomeShow = GetRequestInt("GoodsHomeShow");
} LabMallSupplierResponse response = Supplier.GetSupplierObj().ExportExcelToSupplier(new LabMallSupplierRequest
{
LabMallSupplierDto = supplier
});
if (response.Code == )
{
return Success(response.ResposeData.ToString());
}
else
{
return Fail(response.ResposeData.ToString());
}
}
#endregion
#region 批量导出供应商(运营)
public LabMallSupplierResponse ExportExcelToSupplier(LabMallSupplierRequest request)
{
SupplierServiceClient obj = new SupplierServiceClient();
try
{
LabMallSupplierResponse response = obj.GetLabMallSupplierList(request);//调用服务端 数据集合 string FileFolder = AppDomain.CurrentDomain.BaseDirectory + "files\\Export\\Excel\\";
string FileName = FileFolder + "供应商管理.xls";//文件存放的路径
string ReturnUrl = "/files/Export/Excel/" + "供应商管理.xls";//需要返回的文件路径
if (!Directory.Exists(FileFolder))//指定路径没有该文件时创建
{
Directory.CreateDirectory(FileFolder);
}
if (File.Exists(FileName))//指定文件存在时删除
{
File.Delete(FileName);
}
MemoryStream ms = new MemoryStream();//创建一个流
IWorkbook workbook = new HSSFWorkbook();//创建workbook
ISheet sheet = workbook.CreateSheet("供应商");//创建sheet
IRow row = sheet.CreateRow();//创建row ICellStyle style = workbook.CreateCellStyle();//创建单元格样式
IFont font = workbook.CreateFont();//创建字体
font.Boldweight = short.MaxValue;//字体宽度
style.SetFont(font);//添加到样式 //表头
string[] colName = { "ID", "简称", "全称", "供应商类型", "供应商级别", "开户银行", "收款账号", "网址", "地址", "座机", "是否启用", "商城显示", "纳税人识别号", "类型", "法定代表人", "注册资本", "成立日期", "经营期限", "经营范围" };
for (int i = ; i < colName.Length; i++)
{
row.CreateCell(i).SetCellValue(colName[i]);//创建列
row.Cells[i].CellStyle = style;//字体加粗
} List<LabMallSupplierEntity> list = response.LabMallSupplierDtos;
if (list.Count==)
{
return new LabMallSupplierResponse
{
Code = ,
ResposeData = "没有数据"
};
}
for (int i = ; i < list.Count; i++)
{
LabMallSupplierEntity supplier = list[i];
IRow rows = sheet.CreateRow(i + );
rows.CreateCell().SetCellValue(supplier.LabMallSupplierID);
rows.CreateCell().SetCellValue(supplier.Name == null ? "" : supplier.Name.Trim());
rows.CreateCell().SetCellValue(supplier.FullName == null ? "" : supplier.FullName.Trim());
rows.CreateCell().SetCellValue(supplier.SupplierType == ? "直销" : "经销");
rows.CreateCell().SetCellValue(supplier.SupplierLevel == ? "合约供应商" : "普通供应商");
rows.CreateCell().SetCellValue(supplier.BankName == null ? "" : supplier.BankName.Trim());
rows.CreateCell().SetCellValue(supplier.BankCardNumber == null ? "" : supplier.BankCardNumber.Trim());
rows.CreateCell().SetCellValue(supplier.WebSite == null ? "" : supplier.WebSite.Trim());
rows.CreateCell().SetCellValue(supplier.Address == null ? "" : supplier.Address.Trim());
rows.CreateCell().SetCellValue(supplier.Phone == null ? "" : supplier.Phone.Trim());
rows.CreateCell().SetCellValue(supplier.LabMallSupplierIsEnable == ? "禁用" : "启用");
rows.CreateCell().SetCellValue(supplier.GoodsHomeShow == ? "显示" : "隐藏");
rows.CreateCell().SetCellValue(supplier.IdentityNum == null ? "" : supplier.IdentityNum.Trim());
rows.CreateCell().SetCellValue(supplier.Type == null ? "" : supplier.Type.Trim());
rows.CreateCell().SetCellValue(supplier.Representative == null ? "" : supplier.Representative.Trim());
rows.CreateCell().SetCellValue(supplier.RegisterCapital == null ? "" : supplier.RegisterCapital.Trim());
rows.CreateCell().SetCellValue(supplier.BirthDate.GetString() == null ? "" : supplier.BirthDate.GetString());
rows.CreateCell().SetCellValue(supplier.EndDate.GetString() == null ? "" : supplier.EndDate.GetString());
rows.CreateCell().SetCellValue(supplier.RunScope == null ? "" : supplier.RunScope.Trim());
}
workbook.Write(ms);
ms.Flush();
ms.Position = ; using (FileStream fs=new FileStream(FileName,FileMode.Create,FileAccess.Write))
{
byte[] data = ms.ToArray();
fs.Write(data, , data.Length);
fs.Flush();
data = null;
}
response.Code = ;
response.ResposeData = ReturnUrl;
return response;
}
catch (Exception ex)
{
LogHelp.Error(ex, request.LabMallSupplierDto);
return new LabMallSupplierResponse
{
Code = ,
ResposeData = ex.Message
};
}
finally
{
obj.Close();
}
}
#endregion
.net layui 批量导出的更多相关文章
- 批量导出access某表内容到word文档
一.需求: 需要将表中每一条记录中的某些内容导出在一个word文档中,并将这些文档保存在指定文件夹目录下 二.界面,简单设计如下: 三.添加office相关引用 添加后可在解决方案资源管理器中看到: ...
- 分享一个批量导出当前实例下的所有linkedserver脚本
分享一个批量导出当前实例下的所有linkedserver脚本 很多时候,我们都需要导出实例下面的登录用户,job,linkedserver等等 导出job比较复杂,下午写了一个脚本把所有的linked ...
- Max批量导出工具
Max批量导出工具 http://www.paulneale.com/scripts/batchItMax/batchItMax.htm Scripts Batch It Max: Batch It ...
- python批量导出导入MySQL用户的方法
这篇文章主要介绍了 数据库迁移(A -> B),需要把用户也迁移过去,而用户表(mysql.user)有上百个用户.有2种方法进行快速迁移: 1,在同版本的条件下,直接备份A服务器的mysql数 ...
- ATF批量导出工具
ATF批量导出工具 08 / 31, 2013 批量导出Atf的工具,使用是adobe atf 编码核心 先说一下关于atf的bug 当atf导出时候启用了mips选项会导致:如果纹理问长方形时上传会 ...
- MVC批量导出数据方法
近段时间做了个数据平台,其中涉及到批量导出CSV格式数据的业务,主要使用了部分视图和视图之间传值等知识点,今天做了下整理,特此分享下: 主要分为四步: 1:要打印的数据格式陈列View: 2:自定义导 ...
- C# 导出word文档及批量导出word文档(3)
在初始化WordHelper时,要获取模板的相对路径.获取文档的相对路径多个地方要用到,比如批量导出时要先保存文件到指定路径下,再压缩打包下载,所以专门写了个关于获取文档的相对路径的类. #regio ...
- C# 导出word文档及批量导出word文档(1)
这里用到了两个dll,一个是aspose.word.dll,另外一个是ICSharpCode.SharpZipLib.dll,ICSharpCode.SharpZipLib.dll是用于批量 ...
- C# 导出word文档及批量导出word文档(4)
接下来是批量导出word文档和批量打印word文件,批量导出word文档和批量打印word文件的思路差不多,只是批量打印不用打包压缩文件,而是把所有文件合成一个word,然后通过js来调用 ...
随机推荐
- for for in 给已有的li绑定click事件生成新的li也有click事件
想要给已有的li元素绑定一个click事件,点击生成新的li元素,并且新的li元素也要有click事件 //不能用for循环给每个li绑定click事件 因为这样的话 后面新生成的li就没有click ...
- Mycat 配置文件rule.xml
rule.xml配置文件定义了我们对表进行拆分所涉及到的规则定义.我们可以灵活的对表使用不同的分片算法,或者对表使用相同的算法但具体的参数不同. 该文件里面主要有tableRule和function这 ...
- Spring 事务注解@Transactional
事务管理一般有编程式和声明式两种,编程式是直接在代码中进行编写事物处理过程,而声名式则是通过注解方式或者是在xml文件中进行配置,相对编程式很方便. 而注解方式通过@Transactional 是常见 ...
- quartz-scheduler定时器实现
第一步,在pom.xml中引入quartz-scheduler. <dependency> <groupId>org.quartz-scheduler</groupId& ...
- Flume初见与实践
Photo by Janke Laskowski on Unsplash 参考书籍:<Flume构建高可用.可扩展的海量日志采集系统> --Hari Shreedharan 著 以下简称& ...
- 蓝松短视频SDK基本功能免费列表
下载地址:https://github.com/LanSoSdk/LanSoEditor_common 功能免费. 个人和公司都可以商用,不需要和我们说明. 直接下载, 直接去用既可. 完全不需要和我 ...
- .net core 3.0 Signalr - 04 使用Redis做底板来支持横向扩展
在实际的系统中,可能需要多台机器部署;然而,Signalr的连接信息是跟站点走的,举个例子 推送系统部署了A.B两个服务器,张三访问A服务器,李四访问B服务器,当张三通过A服务器向李四推送的时候,A服 ...
- Yii2 前后台登陆退出分离、登陆验证
这里用的yii2高级模板, 基本模板的配置文件在一个文件里,方法基本没什么区别, 1.用户表要有两个用户表, 当然一个也行,分开是省得麻烦,既然是分离了就彻底分开, 前台表user,后台表user_b ...
- Flume 学习笔记之 Flume NG高可用集群搭建
Flume NG高可用集群搭建: 架构总图: 架构分配: 角色 Host 端口 agent1 hadoop3 52020 collector1 hadoop1 52020 collector2 had ...
- idea中的java web项目(添加jar包介绍)和java maven web项目目录结构
java web项目 web项目下web根目录名称是可以更改的 idea中新建java web项目,默认src为Sources Root,当然也可以手动改,在Sources Root下右键只能新建Pa ...