Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Tue Nov 08, 2016 3:44 pm

Hello,

The code below generates an error: Stack Empty
Spire.Doc: 5.8.13.3040

Code: Select all
DataTable parent = new DataTable("Parent");
parent.Columns.Add("Id");

DataTable childCollection1 = new DataTable("ChildCollection1");
childCollection1.Columns.Add("ParentId");
childCollection1.Columns.Add("Content");

DataTable childCollection2 = new DataTable("ChildCollection2");
childCollection2.Columns.Add("ParentId");
childCollection2.Columns.Add("Content");

parent.Rows.Add("1");
//childCollection1.Rows.Add("1", "test1");
childCollection2.Rows.Add("1", "test2");

DataSet dataSet = new DataSet();
dataSet.Tables.Add(parent);
dataSet.Tables.Add(childCollection1);
dataSet.Tables.Add(childCollection2);

List<DictionaryEntry> list = new List<DictionaryEntry>
{
    new DictionaryEntry("Parent", String.Empty),
    new DictionaryEntry("ChildCollection1", "ParentId = %Parent.Id%"),
    new DictionaryEntry("ChildCollection2", "ParentId = %Parent.Id%")
};

Document document = new Document();
document.LoadFromFile("template.doc", FileFormat.Doc);

document.MailMerge.HideEmptyGroup = true;

document.MailMerge.ExecuteWidthNestedRegion(dataSet, list);

document.ViewSetup.DocumentViewType = DocumentViewType.PrintLayout;
document.SaveToFile("document.doc");


template:
Code: Select all
«TableStart:Parent»
«TableStart:ChildCollection1»
Content: «Content»
«TableEnd:ChildCollection1»
#
«TableStart:ChildCollection2»
Content: «Content»
«TableEnd:ChildCollection2»
«TableEnd:Parent»


Thanks,
Damian

czacha08
 
Posts: 2
Joined: Wed Nov 02, 2016 10:47 am

Wed Nov 09, 2016 6:39 am

Hi,

Thanks for your inquiry. The reason of the problem is that the lack of matching data. So please try to release the code
Code: Select all
childCollection1.Rows.Add("1", "test1");

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Wed Nov 09, 2016 8:05 am

Hi,

My problem assumes that might be missing one element.
Is this case an empty group should not be removed?

document.MailMerge.HideEmptyGroup = true;

Thanks,
Damian

czacha08
 
Posts: 2
Joined: Wed Nov 02, 2016 10:47 am

Thu Nov 10, 2016 6:11 am

Hello,

Could you please provide us your template file to help us look into it?

Thanks,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Return to Spire.Doc