水晶报表(Microsoft 报表)入门常见问题

来源:互联网 发布:云宫迅音 知乎 编辑:程序博客网 时间:2024/05/29 15:36

1.页面尺寸设置:
在设计页面指定页面尺寸,页边距后,工作区中所有可设计区域均为页面可打印区域.因此在设计时不用考虑页边距.或者在设计时将页边距设为0,则工作区中所有可设计区域即为打印区域.
2.内容过长时自动换行延伸:
设置对象的CanGrow为true可实现内容过长自动换行延伸.为保持表格线保持正常衔接,设置表格线的ExtendToBottomOfSection为true.
3.防止页眉结尾表格与详细资料开始表格交接而导致表格线变宽:
设置页眉结尾表格top属性为该区域高度,即表格位于该区域最下方.
设置详细资料开始表格top属性为0,即表格位于该区域最上方.
4.去掉字段的下划线:
在字体属性中设置.
5.crystalReportViewer动态加载报表:
CrystalDecisions.CrystalReports.Engine.TextObject headTextObject=null;
if (this.printType == 1)
{
CrystalReport1 crystalReport1 = new CrystalReport1();
crystalReport1.SetDataSource((DataTable)this.printDataSet.Table1);
headTextObject = (TextObject)crystalReport1.Section1.ReportObjects["toTitle"];
this.crystalReportViewer1.ReportSource = crystalReport1;
}
else if (this.printType == 2)
{
CrystalReport2 crystalReport2 = new CrystalReport2();
crystalReport2.SetDataSource((DataTable)this.printDataSet.Table2);
headTextObject = (TextObject)crystalReport2.Section1.ReportObjects["toTitle"];
this.crystalReportViewer1.ReportSource = crystalReport2;
}
headTextObject.Text = "表头"
6.设置报表中某对象toTitle并设置值:见5.

以下为Microsoft 报表
1.Microsoft ReportViewer动态加载报表:
BindingSource bindingSource = new BindingSource();
if (this.printType == 1)
{
this.reportViewer1.LocalReport.ReportEmbeddedResource = "命名空间.报表文件名1.rdlc"
ReportDataSource reportDataSource = new ReportDataSource("数据集1", bindingSource);
//数据集1 此处的数据集名称一定要和报表设计时指定的数据集名称一致.
this.reportViewer1.LocalReport.DataSources.Add(reportDataSource);
bindingSource.DataSource = this.printDataSet.Table1;
}
else if (this.printType == 2)
{
this.reportViewer1.LocalReport.ReportEmbeddedResource = "命名空间.报表文件名2.rdlc"
ReportDataSource reportDataSource = new ReportDataSource("数据集2", bindingSource);
this.reportViewer1.LocalReport.DataSources.Add(reportDataSource);
bindingSource.DataSource = this.printDataSet.Table2;
}
this.reportViewer1.RefreshReport();
2.在报表中添加自定义参数.
打开报表参数对话框,可在该对话框中加入报表参数,需要注意的是,参数设置中有一项"内部",该设置含义不是很准确,选中该选项后参数则变为只读,不能在程序中动态改变.
如添加参数为title,类型为string,可通过以下方式传参数值.
ReportParameter rptParaA = new ReportParameter("title", "测试报表参数");
reportViewer1.LocalReport.SetParameters(new ReportParameter[] { rptParaA });
然后在页面中添加文本,值为=Parameters!title.Value,则可将该参数显示在报表中.

原创粉丝点击