Devexpress XtraReports的使用

1、报表设计

在报表属性中,设置默认font为微软雅黑,设置Language为默认(注意:不能设置为中文,否则导出PDF中文乱码)。

imageimage

2、报表后台代码

绑定到List类型的绑定方法,设置报表上的对象的XRBinging中DataSource参数为null。

从报表的DataMember 需要设置,否则从报表只显示一条记录。

同时“计算”字段的表达式的使用。

public partial class MyReport : DevExpress.XtraReports.UI.XtraReport
{
    public MyReport()
    {
        InitializeComponent();

        this.xrLabel6.DataBindings.Add("Text", null, "FileNo");
        this.xrLabel7.DataBindings.Add("Text", null, "ApplyTime", "{0:yyyy-MM-dd}");

        CalculatedField calculatedField1 = new CalculatedField
        {
            Expression = "Iif([InspectItms.InspectResult]==1,'合格','不合格' )",
            Name = "calculatedField1"
        };
        CalculatedField calculatedField2 = new CalculatedField
        {
            Expression = "[ReviewResult]=='1'",
            Name = "calculatedField2"
        };

        this.CalculatedFields.AddRange(new DevExpress.XtraReports.UI.CalculatedField[] { calculatedField1, calculatedField2});
        
        DetailReport.DataMember = "InspectItms";
        this.xrTableCell5.DataBindings.Add("Text", null, "InspectItms.InspectItem");
        this.xrTableCell6.DataBindings.Add("Text", null, "calculatedField1");
        this.xrCheckBox1.DataBindings.Add("Checked", null, "calculatedField2");

    }
}

3、调用报表

List<MyEntity> list = new List<MyEntity> { entity };
MyReport myReport = new MyReport(); //报表实例
myReport.DataSource = list;//绑定报表的数据源
myReport.ShowPreview();

猜你喜欢

转载自www.cnblogs.com/springsnow/p/12468892.html