Använda anonyma typer eller anpassade objekt i Aspose.Cells
Contents
[
Hide
]
Aspose.Cells stödjer också anonyma typer eller anpassade objekt i smarta markörer. I nedanstående exempel behöver klassen Product definieras innan den används.
//Instantiate the workbookdesigner object.
WorkbookDesigner report = new WorkbookDesigner();
//Get the first worksheet(default sheet) in the workbook.
Aspose.Cells.Worksheet w = report.Workbook.Worksheets[0];
//Input some markers to the cells.
w.Cells["A1"].PutValue("Test");
w.Cells["A2"].PutValue("&=MyProduct.Name");
w.Cells["B2"].PutValue("&=MyProduct.Age");
//Instantiate the list collection based on the custom class.
IList<MyProduct> list = new List<MyProduct>();
//Provide values for the markers using the custom class object.
list.Add(new MyProduct("Simon", 30));
list.Add(new MyProduct("Johnson", 33));
//Set the data source.
report.SetDataSource("MyProduct", list);
//Process the markers.
report.Process(false);
//Save the excel file.
report.Workbook.Save("Smart Marker Customobjects.xls");