public class Product { public int Id { get; set; } public string Name { get; set; } public string Name2 { get; set; } public string Name3 { get; set; } public string Name4 { get; set; } } public class ProductList : ObservableCollection<Product> { public ProductList() { for (int i = 1; i < 40000; i++) Add(new Product() { Name = "A", Name2 = "B", Name3 = "C", Name4 = "E", Id = i }); } } private void Button_Click(object sender, RoutedEventArgs e) { dynamic excelApp; excelApp = AutomationFactory.CreateObject("Excel.Application"); dynamic workbook = excelApp.workbooks; workbook.Add(); dynamic sheet = excelApp.ActiveSheet; dynamic cell = null; int index = 1; foreach (Product emp in grid.ItemsSource) { cell = sheet.Cells[index, 1]; cell.Value = emp.Name; cell = sheet.Cells[index, 2]; cell.Value = emp.Name2; cell = sheet.Cells[index, 3]; cell.Value = emp.Name3; cell = sheet.Cells[index, 4]; cell.Value = emp.Name4; cell = sheet.Cells[index, 5]; cell.Value = emp.Id; index++; } excelApp.Visible = true; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)