public static void Run()
{
// ExStart:1
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
Workbook workbook = new Workbook();
// Create a designer workbook
// Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
worksheet.Cells["A1"].PutValue("Husband Name");
worksheet.Cells["A2"].PutValue("&=Husband.Name");
worksheet.Cells["B1"].PutValue("Husband Age");
worksheet.Cells["B2"].PutValue("&=Husband.Age");
worksheet.Cells["C1"].PutValue("Wife's Name");
worksheet.Cells["C2"].PutValue("&=Husband.Wives.Name");
worksheet.Cells["D1"].PutValue("Wife's Age");
worksheet.Cells["D2"].PutValue("&=Husband.Wives.Age");
// Apply Style to A1:D1
Range range = worksheet.Cells.CreateRange("A1:D1");
Style style = workbook.CreateStyle();
style.Font.IsBold = true;
style.ForegroundColor = Color.Yellow;
style.Pattern = BackgroundType.Solid;
StyleFlag flag = new StyleFlag();
flag.All = true;
range.ApplyStyle(style, flag);
// Initialize WorkbookDesigner object
WorkbookDesigner designer = new WorkbookDesigner();
// Load the template file
designer.Workbook = workbook;
System.Collections.Generic.List<Husband> list = new System.Collections.Generic.List<Husband>();
// Create an object for the Husband class
Husband h1 = new Husband("Mark John", 30);
// Create the relevant Wife objects for the Husband object
h1.Wives = new List<Wife>();
h1.Wives.Add(new Wife("Chen Zhao", 34));
h1.Wives.Add(new Wife("Jamima Winfrey", 28));
h1.Wives.Add(new Wife("Reham Smith", 35));
// Create another object for the Husband class
Husband h2 = new Husband("Masood Shankar", 40);
// Create the relevant Wife objects for the Husband object
h2.Wives = new List<Wife>();
h2.Wives.Add(new Wife("Karishma Jathool", 36));
h2.Wives.Add(new Wife("Angela Rose", 33));
h2.Wives.Add(new Wife("Hina Khanna", 45));
// Add the objects to the list
list.Add(h1);
list.Add(h2);
// Specify the DataSource
designer.SetDataSource("Husband", list);
// Process the markers
designer.Process();
// Autofit columns
worksheet.AutoFitColumns();
// Save the Excel file.
designer.Workbook.Save(dataDir + "output.xlsx");
// ExEnd:1
}
}