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调用 ...
随机推荐
- 关于volatile
也许读者会注意到,端口寄存器的变量使用了volatile 修饰符,这是因为C语言在编译的时候会进行某种优化来提高效率,比如下面这段代码int i = 1;int a = i;int b = i;对于编 ...
- C#使用.net.mail配置163邮箱报错:不允许使用邮箱名称。 服务器响应为:authentication is required,smtp9,DcCowABHK4UYE11W2k6fAQ--.52196S2 1448940312
client.UseDefaultCredentials = true; 要放在 client.Credentials = new NetworkCredential("用户名", ...
- 用Nginx实现Session共享的均衡负载
前言 大学三年多,也做个几个网站和APP后端,老是被人问到,如果用户多了服务器会不会挂,总是很尴尬的回答:“哈哈,我们的用户还少,到了服务器撑不住的时候,估计都上市了吧”.说是这么说,但是对于有强迫症 ...
- USB Video Class及其实现
1 Video Class 基础概念Usb协议中,除了通用的软硬件电气接口规范等,还包含了各种各样的Class协议,用来为不同的功能定义各自的标准接口和具体的总线上的数据交互格式和内容.这些Class ...
- hdu 2853
虚拟赛一开始lyf就对我说这是一道匹配的题目,我一看明显裸的最优匹配,敲完提交wrong, 题目要求改变尽量少的公司,就是如果遇到相等的权值,优先选择跟他原来匹配的,KM匹配是按序号大小来的,如果一个 ...
- (LeetCode)两个队列来实现一个栈
原题例如以下: Implement the following operations of a stack using queues. push(x) -- Push element x onto s ...
- [manacher] hdu 3294 Girls' research
题意: 给一个字符x代表真实的a 然后输出的时候转换 然后就是求最长回文子串的串是什么 长度要大于1 思路: 就是裸的manacher,弄清楚下标的转换关系就好了 代码: #include" ...
- 辛星解读mysql的用户管理
可能做开发的多半不太关注这方面,可是要说到做运维.那就不能不关注了.由于我们都知道,root的权限太大了.不是随便能用的.我们平时最好用一些比較低的权限的用户.这样会让我们的安全性大大提高,也能防止我 ...
- Linux中图形界面和文本模式相互切换
1.默认开机进入文本模式 如果想让开机自动进纯文本模式, 修改/etc/inittab 找到其中的 id:5:initdefault: 这行指示启动时的运行级是5,也就是图形模式 改成3就是文本模式了 ...
- HTML与CSS入门——第十二章 在网页中使用多媒体
知识点: 1.如何链接多媒体文件 2.如何嵌入多媒体文件 3.使用多媒体的更多技巧 多媒体文件:音频,视频和动画,以及静态的图像和文本. 这里我就直接讲HTML5了…… 此前都是用ojbect来加载或 ...