TX Text Control系列教程—Windows Forms:使用对象作为数据源

直接使用可枚举的业务对象作为数据源来合并模板是TX Text Control Reporting的典型方案之一。

TX Text Control .NET for Windows Forms 是一套功能丰富的文字处理控件,它以可重复使用控件的形式为开发人员提供了Word中常用的文字处理功能,对于需要强大且灵活的文档处理能力的应用程序而言,是理想的选择。

TX Text Control .NET for Windows Forms X19试用版


直接使用可枚举的业务对象作为数据源来合并模板是TX Text Control Reporting的典型方案之一。

使用IEnumerable对象作为数据源

MailMerge将集合中对象的所有公共属性解释为表列和子表。 IEnumerable类型的属性会自动实例化为关系,并用于合并块和嵌套合并块。考虑以下类结构作为数据源:

TX Text Control系列教程—Windows Forms:使用对象作为数据源

以下是代表以上UML类设计的代码:

public class Invoice{    public List<Product> Products    {        get;        set;    }    public Customer Customer    {        get;        set;    }}public class Product{    public Product(string Name, Decimal Price)    {        this.Name = Name;        this.Price = Price;    }    public string Name    {        get;        set;    }    public Decimal Price    {        get;        set;    }}

该模板包含一个名为Products的合并块。 块中的合并字段名为“名称”和“价格”。

TX Text Control系列教程—Windows Forms:使用对象作为数据源

以下代码显示了如何创建数据源对象以及如何使用MergeObjects启动合并过程:

Invoice invoice = new Invoice();invoice.Products = new List<Product>();invoice.Products.Add(new Product("Apple", 3.55m));invoice.Products.Add(new Product("Banana", 2.4m));invoice.Products.Add(new Product("Pineapple", 2.99m));var invoices = new List<Invoice>();invoices.Add(invoice);mailMerge1.MergeObjects(invoices);

文章推荐:

TX Text Control系列教程—Windows Forms:创建应用程序


如果您对Text Control感兴趣,可以咨询在线客服>>购买正版授权软件。

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年1月11日
下一篇 2021年1月11日

相关推荐

发表回复

登录后才能评论