I'm facing an issue with the MailMerge.ExecuteWidthNestedRegion method when I have records without child records. I'm using the dot net standard edition. I've created a small application to demonstrate the problem.
- Code: Select all
class Program {
public class Order {
public Int32 OrderId { get; set; }
public String OrderName { get; set; }
}
public class OrderProduct {
public Int32 ProductId { get; set; }
public Int32 OrderId { get; set; }
public String ProductName { get; set; }
public String ProductAndOrderId {
get { return String.Format("{0}|{1}", this.ProductId, this.OrderId); }
}
}
public class OrderProductOption {
public Int32 ProductId { get; set; }
public Int32 OrderId { get; set; }
public String OptionName { get; set; }
public String ProductAndOrderId {
get { return String.Format("{0}|{1}", this.ProductId, this.OrderId); }
}
}
static void Main(string[] args) {
List<Order> orders = new List<Order>() {
new Order() {OrderId = 1, OrderName = "First order"},
new Order() {OrderId = 2, OrderName = "Second order"},
new Order() {OrderId = 3, OrderName = "Third order"},
new Order() {OrderId = 4, OrderName = "Fourth order (empty)"}
};
List<OrderProduct> orderproducts = new List<OrderProduct>() {
new OrderProduct() {OrderId = 1, ProductId = 1, ProductName = "55 INCH TV"},
new OrderProduct() {OrderId = 1, ProductId = 2, ProductName = "DVD Player"},
new OrderProduct() {OrderId = 2, ProductId = 3, ProductName = "iPhone"},
new OrderProduct() {OrderId = 3, ProductId = 1, ProductName = "55 INCH TV"}
};
List<OrderProductOption> orderproductoptions = new List<OrderProductOption>() {
new OrderProductOption() {OrderId = 1, ProductId = 1, OptionName = "Remote control"},
new OrderProductOption() {OrderId = 1, ProductId = 1, OptionName = "Wall mount"},
new OrderProductOption() {OrderId = 2, ProductId = 3, OptionName = "Cable"},
new OrderProductOption() {OrderId = 3, ProductId = 1, OptionName = "Wall mount"},
};
List<DictionaryEntry> relationsList = new List<DictionaryEntry>();
MailMergeDataSet mailMergeDataSet = new MailMergeDataSet();
mailMergeDataSet.Add(new MailMergeDataTable("Orders", orders));
mailMergeDataSet.Add(new MailMergeDataTable("OrderProducts", orderproducts));
mailMergeDataSet.Add(new MailMergeDataTable("OrderProductOptions", orderproductoptions));
relationsList.Add(new DictionaryEntry("Orders", string.Empty));
relationsList.Add(new DictionaryEntry("OrderProducts", "OrderId = %Orders.OrderId%"));
relationsList.Add(new DictionaryEntry("OrderProductOptions", "ProductAndOrderId = %OrderProducts.ProductAndOrderId%"));
Document document = new Document(@"D:\SpirePoc\Poc.docx", FileFormat.Auto);
//document.IsUpdateFields = true;
document.MailMerge.ClearFields = true;
document.MailMerge.HideEmptyGroup = true;
//document.MailMerge.HideEmptyParagraphs = true;
document.MailMerge.ExecuteWidthNestedRegion(mailMergeDataSet, relationsList);
document.SaveToFile(@"D:\SpirePoc\Poc-Result.docx");
}
}
I'm having two problems here:
- The ordered DVD player in the first order doesn't have options, but it shows "Cable"
- The fourth order doesn't have any ordered products nor product options, but it shows the products placeholder and all options.
I've attached the template doc and the result.
Thanks in advance,
Bart