datagrid指定行合并导出
导出代码:
public void GridViewToExcel(GridView ctrl, string FileType, string FileName)
{
HttpContext.Current.Response.Charset = "GB2312";
HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
HttpContext.Current.Response.AppendHeader("Content-Disposition",
"attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
HttpContext.Current.Response.ContentType = FileType;//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
ctrl.Page.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
ctrl.AllowPaging = false;
bind();
ctrl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
ctrl.AllowPaging = true;
bind();
}
重写方法,此方法必须需要:
public override void VerifyRenderingInServerForm(Control control)
{
}
指定合并列:
protected void GridView1_DataBound(object sender, EventArgs e)
{
int[] arr = new int[] { 1,3,5 };
GroupRows(GridView1, arr, 2);
GroupRows(GridView1, arr, 0);
GroupRows(GridView1, arr, 1);
}
//合并
public static void GroupRows(GridView GridView1, int[] cellIndex, int mostlyid)
{
int i = 0, rowSpanNum = 1;
while (i < GridView1.Rows.Count - 1)
{
GridViewRow gvr = GridView1.Rows[i];
for (++i; i < GridView1.Rows.Count; i++)
{
GridViewRow gvrNext = GridView1.Rows[i];
if (gvr.Cells[cellIndex[mostlyid]].Text == gvrNext.Cells[cellIndex[mostlyid]].Text)// && gvr.Cells[cellIndex[mostlyid]].Text == gvrNext.Cells[cellIndex[mostlyid]].Text)
{
gvrNext.Cells[cellIndex[mostlyid]].Visible = false;//不然会把其他的挤走,造成行突出
rowSpanNum++;
}
else
{
gvr.Cells[cellIndex[mostlyid]].RowSpan = rowSpanNum;
rowSpanNum = 1;
break;
}
if (i == GridView1.Rows.Count - 1)
{
gvr.Cells[cellIndex[mostlyid]].RowSpan = rowSpanNum;
}
}
}
}
datagrid指定行合并导出的更多相关文章
- VB datagrid指定行着色
有图有真相: 关键点:使用datagrid的FetchRowStyle委托. (Form界面的datagrid名称:dgv) 使用FetchRowStyle委托,要先打开开关: dgv.FetchRo ...
- C# 使用Epplus导出Excel [4]:合并指定行
C# 使用Epplus导出Excel [1]:导出固定列数据 C# 使用Epplus导出Excel [2]:导出动态列数据 C# 使用Epplus导出Excel [3]:合并列连续相同数据 C# 使用 ...
- NPOI的使用Excel模板导出 可插入到指定行
Excel模版建议把需要添加数据行的样式设置好 模版样式,导出后效果 [2017-11-22 对获取需插入数据的首行样式有时为空报错修改] /// <summary> /// 根据模版导出 ...
- easyui datagrid行合并
easyui datagrid行合并 合并方法 /** * EasyUI DataGrid根据字段动态合并单元格 * 参数 tableID 要合并table的id * 参数 colList 要合并的列 ...
- 【练习】数据移动---parfile导出表中指定行:
要求: ①创建存放数据的文件: ②使用默认的bad文件生成方式: ③使用truncate选项方式. 1.准备条件: [oracle@host03 ~]$ mkdir datadump [oracle@ ...
- (转载)按行合并两个sql的查询结果
(转载)http://blog.csdn.net/wxwstrue/article/details/6784774 Union all join 是平行合并 为水平连接 Union all 是垂直合并 ...
- DataGrid列的合并
/// <summary> /// DataGrid列的合并 /// 注意:1.DataGrid在绑定的时候进行分组和排序,才能让相同的行放在一起 /// 2.方法应用的时机,应该在Dat ...
- linux中文件多行合并为一行的例子
现网中经常遇到匹配到某一关键字下的所有行合并到同一行,再次匹配到相关关键字再和下面的合并,示例如下: # line1ab# line2cde# line3f想要变成: # line1 a b# lin ...
- sed 指定行范围匹配(转)
sed -n '5,10{/pattern/p}' file sed是一个非交互性性文本编辑器,它编辑文件或标准输入 导出的文件拷贝.标准输入可能是来自键盘.文件重定向.字符串或变量,或者是一个管道文 ...
随机推荐
- 杭电oj1236 排名
Tips:此题比较简单,最好将每一个学生的信息构建一个结构体,另外需要注意的是,若分数相同,排序按姓名排序,我看网上很多都是使用<algorithm>中的sort算法,只需重写cmp函数即 ...
- Single NumberII
**一定要注意 == 运算符的优先级高于& 因此在条件判断的时候 必须加括号 class Solution { public: int IsBit1(int num, int place) { ...
- jquery如何获得页面元素的坐标值
http://www.cnblogs.com/pansly/archive/2011/05/25/2056222.html jquery如何获得页面元素的坐标值 yulutxt是输入经典语录的输入 ...
- as3 页游中,新手指导中,屏蔽所有交互对象,但除了指定交互对象可用的方法【转http://blog.csdn.net/linjf520/article/details/9450945】
package { import flash.display.InteractiveObject; import flash.display.Stage; import flash.events.Mo ...
- Sublime Text 3 无法使用package control安装插件解决办法
Crossing's Blog NOT Genius but Try Best 首页 分类 关于 归档 标签 问题貌似出现在liveStyle版本更新之后,因为打算安装javascript next和 ...
- Daily Sentence
2016-12-05 08:59:15 Knowing yourself is the beginning of all wisdom. 智者始于自知. 2016-05-01 19:38:25 The ...
- Repeater隔行变色,两个方式
<table> <tr> <td>用户编号</td> </tr> <asp:Repeater ID="rptUser&quo ...
- android 转帖留链接
Android开发:用Drawable XML绘制带阴影效果的圆形按钮 http://evis.me/2013/05/android-dev-render-button-with-s ...
- NodeJS学习笔记(一)——搭建开发框架Express,实现Web网站登录验证
JS是脚本语言,脚本语言都需要一个解析器才能运行.对于写在HTML页面里的JS,浏览器充当了解析器的角色.而对于需要独立运行的JS,NodeJS就是一个解析器.每一种解析器都是一个运行环境,不但允许J ...
- SQL Server 改变数据库的名字
方法 1: alter database modiry name = new_database_name; ---------------------------------------------- ...