Click here to Skip to main content
15,902,732 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I use the following code for export data to excel in Silverlight 5 web application, it works but speed of exporting is terrible, I want to have exporting time less than 5 sec for 4000 rows count, How can I improve it?
Thanks

C#
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;
    }
Posted

1 solution

 
Share this answer
 
Comments
Angela 10293848 27-Jan-14 7:58am    
thanks, those are helpful links.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900