Importation à partir d objets personnalisés
Contents
[
Hide
]
Les développeurs peuvent importer des données d’une collection d’objets vers une feuille de calcul en utilisant ImportCustomObjects. Vous pouvez fournir une liste de colonnes/propriétés à la méthode pour afficher votre liste d’objets souhaitée.
//Instantiate a new Workbook
Workbook book = new Workbook();
//Clear all the worksheets
book.Worksheets.Clear();
//Add a new Sheet "Data";
Worksheet sheet = book.Worksheets.Add("Data");
//Define List
List<WeeklyItem> list = new List<WeeklyItem>();
//Add data to the list of objects
list.Add(new WeeklyItem() { AtYarnStage = 1, InWIPStage = 2, Payment = 3, Shipment = 4, Shipment2 = 5 });
list.Add(new WeeklyItem() { AtYarnStage = 5, InWIPStage = 9, Payment = 7, Shipment = 2, Shipment2 = 5 });
list.Add(new WeeklyItem() { AtYarnStage = 7, InWIPStage = 3, Payment = 3, Shipment = 8, Shipment2 = 3 });
//We pick a few columns not all to import to the worksheet
sheet.Cells.ImportCustomObjects((System.Collections.ICollection)list,
new string[] { "Date", "InWIPStage", "Shipment", "Payment" },
true,
0,
0,
list.Count,
true,
"dd/mm/yyyy",
false);
//Auto-fit all the columns
book.Worksheets[0].AutoFitColumns();
//Save the Excel file
book.Save("ImportedCustomObjects.xls");