DataGrid导出excel
DAL:
//产品信息导出——LPH
public DataTable ExportRelease(string type)
{
string sql = "SELECT [ProductID],[BankName],[ProductName] ,[IsServiceEnt] ,[IsServiceTrade],[IsServiceIndividual],[IsServiceOT] ,[ServiceOTDesc] ,[IsIndividual],[IsEnterpriseMF],[IsEnterpriseWS],[IsEnterpriseSR],[IsEnterpriseST],[IsEnterpriseOT],[EnterpriseOTDesc] ,[AgeLimit] ,[RegisterAddrType],[BusinessIncome] ,[TotalAssets] ,[NoGuaranty] ,[IsMortgageHS] ,[IsMortgageFB],[IsMortgageME] ,[IsMortgageOT] ,[MortgageOTDesc] ,[IsHypoDR] ,[IsHypoWR],[IsHypoIP],[IsHypoAR],[IsHypoITP],[IsHypoOT],[HypoDesc],[IsGuaranteeInd] ,[IsGuaranteeEnt] ,[IsGuaranteeCom] ,[IsGuaranteeOT] ,[GuaranteeOTDesc] ,[LoanAmountUpper] ,[LoanAmountLower] ,[LoanLimitUpper] ,[LoanLimitLower] ,[RepaymentType] ,[ReviewDate] ,[ProductDesc],[ProductDoc],[ProductURL] FROM [LoanProducts] where IsDeleted=0 and CheckStatus=3";
return base.SelectData(sql);
}
BLL:
//产品信息导出——LPH
protected DataTable ExportRelease(string type)
{
LP_CustomerDetailDAL dal = new LP_CustomerDetailDAL(CurrentTransaction);
return dal.ExportRelease(type);
}
protected void btnExcel_Click(object sender, EventArgs e)
{
System.Data.DataTable dt = (System.Data.DataTable)EventSubmit("TonkNet.BDA.LoanProduct.BLL.LoanProduct.LP_CustomerDetailBLL", "ExportRelease", new object[] { "" });
DataTableToExcel(dt, "产品信息导出列表" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
//ExportExcel(dt, 100);
}
/// <summary>
/// 把datatable导入到excel中——LPH
/// </summary>
/// <param name="dt">DataTable</param>
/// <param name="defaultFileName">默认保存文件名</param>
protected void DataTableToExcel(System.Data.DataTable dt, string defaultFileName)
{
DataGrid dgd = new DataGrid();
dgd.AutoGenerateColumns = false;
//添加字段
BoundColumn ProductID = new BoundColumn();
BoundColumn BankName = new BoundColumn();
BoundColumn ProductName = new BoundColumn();
BoundColumn IsServiceEnt = new BoundColumn();
BoundColumn IsServiceTrade = new BoundColumn();
BoundColumn IsServiceIndividual = new BoundColumn();
//将多余的一行隐藏掉
ProductID.HeaderStyle.Height = 0;
BankName.HeaderStyle.Height = 0;
ProductName.HeaderStyle.Height = 0;
IsServiceEnt.HeaderStyle.Height = 0;
IsServiceTrade.HeaderStyle.Height = 0;
IsServiceIndividual.HeaderStyle.Height = 0;
//ProductID.HeaderText = "序号";
//BankName.HeaderText = "银行名称";
//ProductName.HeaderText = "产品名称";
//IsServiceEnt.HeaderText = "企业流动资金贷款";
//IsServiceTrade.HeaderText = "贸易融资";
//IsServiceIndividual.HeaderText = "个人经营性贷款";
ProductID.DataField = "ProductID";
BankName.DataField = "BankName";
ProductName.DataField = "ProductName";
IsServiceEnt.DataField = "IsServiceEnt";
IsServiceTrade.DataField = "IsServiceTrade";
IsServiceIndividual.DataField = "IsServiceIndividual";
dgd.Columns.Add(ProductID);
dgd.Columns.Add(BankName);
dgd.Columns.Add(ProductName);
dgd.Columns.Add(IsServiceEnt);
dgd.Columns.Add(IsServiceTrade);
dgd.Columns.Add(IsServiceIndividual);
dgd.DataSource = dt.DefaultView;
dgd.DataBind();
if (dgd.Items.Count == 0)
{
throw (new Exception("there is no data in dateTable"));
}
else
{
string elxStr = "<table border='1px' style='text-align:center;font-weight :bold ;'><tr> <td rowspan='4'>序号</td> <td rowspan='4'>银行名称</td> <td rowspan='4'>产品名称</td> <td rowspan='3' colspan='4'>业务实质</td> <td colspan='6'>贷款主体</td> <td rowspan='4'>企业成立最短年限(不限选0)</td> <td rowspan='4'>企业注册地</td><td rowspan='4'>营业收入(万元)</td><td rowspan='4'>企业总资产(万元)</td><td colspan='15'>担保方式</td><td rowspan='3' colspan='2'>额度(万元)</td><td rowspan='3' colspan='2'>贷款期限(月)</td><td rowspan='4'>还款方式</td><td rowspan='4'>审批时间</td><td rowspan='4'>产品特点(50字以内,内容通俗易懂)</td><td rowspan='4'>申请所需特殊文件(50字以内)</td><td rowspan='4'>产品链接或热线电话</td></tr><tr><td rowspan='3'>个人</td><td rowspan='2' colspan='5'>企业类型</td><td rowspan='3'>不需要</td><td colspan='14'>需要</td></tr><tr><td colspan='4'>抵押</td><td colspan='6'>质押</td><td colspan='4'>保证</td> </tr><tr><td>企业流动资金贷款</td><td>贸易融资</td><td>个人经营性贷款</td><td>其他(请注明)</td><td>制造业</td><td>批发、零售</td><td>服务业</td><td>科技型</td><td>其他(请说明)</td><td>商业房产</td><td>厂房</td><td>机器设备</td><td>其他(请注明)</td><td>存单</td><td>仓单</td><td>保单</td><td>应收账款</td><td>知识产权</td><td>其他(请注明)</td><td>个人连带责任担保</td><td>企业担保</td><td>担保公司担保</td><td>其他(请注明)</td><td>下限</td><td>上限</td><td>下限</td><td>上限</td></tr></table>";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Charset = "gb2312";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + defaultFileName);
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GBK");
//HttpContext.Current.Response.ContentEncoding = Encoding.UTF7;
//设置输出流为简体中文,试了GBK会出现乱码
HttpContext.Current.Response.ContentType = "application/ms-excel";
//设置输出文件类型为excel文件。
CultureInfo myCItrad = new CultureInfo("ZH-CN", true);
StringWriter oStringWriter = new StringWriter(myCItrad);
Response.Write(elxStr);
HtmlTextWriter oHtmlTextWriter = new HtmlTextWriter(oStringWriter);
dgd.RenderControl(oHtmlTextWriter);
HttpContext.Current.Response.Write(oStringWriter.ToString());
HttpContext.Current.Response.End();
}
}
DataGrid导出excel的更多相关文章
- easyui datagrid导出excel
[第十四篇]easyui datagrid导出excel <a class="btn btn-app" onclick="exportExcel()" ...
- Jquery easyui datagrid 导出Excel
From:http://www.cnblogs.com/weiqt/articles/4022399.html datagrid的扩展方法,用于将当前的数据生成excel需要的内容. 1 <sc ...
- 【第十四篇】easyui datagrid导出excel
<a class="btn btn-app" onclick="exportExcel()"><i class="fa fa-edi ...
- .NET DataGrid 导出Excel 无分页
#region 导出Excel // protected void BtnExcelClick(object sender, EventArgs e) { ToExcel(); } public vo ...
- WPF DataGrid 导出Excel
#region Excel导出 private void btnExportExcel_Click(object sender, RoutedEventArgs e) { Export(this.dg ...
- WPF中将DataGrid导出Excel
int number = 1; private void MenuItem_Click(object sender, RoutedEventArgs e) { #region string path ...
- 把旧系统迁移到.Net Core 2.0 日记(8) - EASYUI datagrid+ Dapper+ 导出Excel
迁移也没太大变化,有一个, 之前的Request.QueryString 是返回NameValueCollection, 现在则是返回整个字符串. 你要改成Request.Query[“key”] 直 ...
- MVC项目中怎样用JS导出EasyUI DataGrid为Excel
在做一中考评项目的时候,遇到了这么一个需求.就是把评教后得到的老师的成绩导出为Excel.事实上需求非常普通.实现起来有些复杂.由于老师考评不但有固定的考核项,还有额外加分项.于是我们就抽出来了一个表 ...
- easyui_datagrid实现导出Excel
easyui_datagrid实现导出Excel 一.PHPExcel使用方法 先下载PHPExcel类库文件,并引入. 二.利用AJAX实现datagrid导出Excel 原理:前台通过AJAX调用 ...
随机推荐
- MySQL常用时间函数
官方文档:Date and Time Functions Name Description ADDDATE() Add time values (intervals) to a date value ...
- linux 命令后台执行
我想把updatedb命令(用于重新建立整盘索引的命令)放在后台运行.因为我不想眼睁睁的看着机器建立索引,我还想编会儿程序呢: # updatedb & [1] 23336 注释:在所要执行的 ...
- puppet foreman
服务器(物理机器和虚拟机)多了以后需要工具来管理,经常登陆系统后不知是在虚拟机上还是在物理机上?如果在虚拟机上这个虚拟机运行在哪个服务器节 点(host)上?如果在物理机上运行在什么配置的物理机上?运 ...
- poj 2376 Cleaning Shifts(贪心)
Description Farmer John <= N <= ,) cows to <= T <= ,,), the first being shift and the la ...
- js bom中浏览器兼容问题判断代码
var btn = document.getElementById('d1');if(addEventListener===undefined){ btn.attachEvent('onclick', ...
- (转载)XML Tutorial for iOS: How To Read and Write XML Documents with GDataXML
In my recent post on How To Choose the Best XML Parser for Your iPhone Project, Saliom from the comm ...
- 《学习opencv》笔记——矩阵和图像操作——cvCalcCovarMatrix,cvCmp and cvCmpS
矩阵和图像的操作 (1)cvCalcCovarMatrix函数 其结构 void cvCalcCovarMatrix(计算给定点的均值和协方差矩阵 const CvArr** vects,//给定向量 ...
- VMware SphereESXi上安装虚拟机
VMware SphereESXi上安装虚拟机 创建新虚拟机 此处以CentOS为例 注意:配置上传的系统文件位置及启动项
- javascript 模仿 html5 placeholder
<form action="?action=deliver" method="post" class="deliver-form"&g ...
- SuperSocket学习笔记(二)
上一篇博客SuperSocket学习笔记(一)说明了怎么快速搭建一个服务器端,这篇文章我想深挖一下SuperSocket 1. 每一个客户端连接到服务器端时,服务器端会将客户端的信息保存到一个Sess ...