java中如何确定表的列宽,如何在RDLC报告中动态调整表格列宽

To make visible columns expand and fill the space of excluded (hidden) columns so that report width is maintained, work needs to be done is as under.

rdlc文件是一个xml文档 . 它将列宽定义为以下xml(这特定于使用Visual Studio 2005创建的RDLC文件,对于其他版本可能不同) . xml下面表示表中有6列 .

0.5in

1.125in

1in

1in

0.5in

1.375in

基本上逻辑很简单,只需增加可见列的宽度即可 . 但它的实现需要很少的代码行 .

计算隐藏列宽度的总和,然后重新计算可见列的宽度

float[] resizedwidth;

// code for recalculation goes here

将整个报告xml读入字符串变量'rptxml'

String rptxml = System.IO.File.ReadAllText(@"D:\SO\WinFormQ\WinFormQ\Report1.rdlc");

用修改后的xml段替换上面的xml段

int start = rptxml.IndexOf("");

int end = rptxml.IndexOf("") + "".Length;

String resizedcolumns = String.format(

""

+ "{0}in"

+ "{1}in"

+ "{2}in"

+ "{3}in"

+ "{4}in"

+ "{5}in"

+ ""

, resizedwidth[0], resizedwidth[1], resizedwidth[2], resizedwidth[3], resizedwidth[4], resizedwidth[5]

);

rptxml = rptxml.Substring(0, start) + resizedcolumns + rptxml.Substring(end);

从字符串变量'rptxml'创建TextReader

TextReader tr = new StringReader(rptxml);

使用LoadReportDefinition()方法加载修改后的报表定义

reportViewer1.LocalReport.LoadReportDefinition(tr);

继续指定DataSources和ReportParameters等,最后显示报告 . 注意:不要忘记关闭TextReader tr.Close() .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值