最近在做三调报表,直接在dev控件中先画出报表模板,然后数据填充利用table控件,如下图:
当建立好报表模板了,开始往每个tablecell里面绑定xml数据源,我遇到的问题是当数据源当中有很多属性的时候,在tablecell里面一个个绑定,一个个去找非常麻烦,下面的报表还算少的,如果遇到有几百几千个字段的报表,如果一个个这样去选定择绑定数据源,太浪费时间,于是,打算用代码实现绑定功能。代码如下:`public void Binddata()
{
DataSet ds = new DataSet();
ds.ReadXmlSchema(xmlFileName);
DataTable dt = ds.Tables[“dt”]; //这个是xml数据源里<xs:element name=“dt”>的名字
DevExpress.XtraReports.UI.XtraReport p_XtraReport = DevExpress.XtraReports.UI.XtraReport.FromFile(repxFileName, true);
XRTable Table = p_XtraReport.FindControl("Table1", true) as XRTable;
XRTableRowCollection xrtableRowCollection = Table.Rows;
int numRow = xrtableRowCollection.Count;
for (int ic = 0; ic < numRow; ic++)
{
XRTableRow xrtableRow = xrtableRowCollection[ic];
XRTableCellCollection xrtableCellCollection = xrtableRow.Cells;
int numColumn = xrtableCellCollection.Count;
for (int ir = 0; ir < numColumn; ir++)
{
XRTableCell xrtableCell = xrtableCellCollection[ir];
string dataMember = dt.Columns[ir + ic * numColumn].ColumnName;
if (xrtableCell.DataBindings.Count > 0)
{
xrtableCell.DataBindings.RemoveAt(0);
}
string name = xrtableCell.Name;
xrtableCell.DataBindings.Add("Text", dt, "dt." + dataMember);//绑定数据源
}
}
p_XtraReport.SaveLayout(repxFileName);
}`
来源:CSDN
作者:一指流沙叹风华
链接:https://blog.csdn.net/weixin_38676065/article/details/104791454