导出到Excel的速度 [英] speed of Export to Excel
本文介绍了导出到Excel的速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我使用以下代码导出数据,以便在Silverlight 5 Web应用程序中表现出色,它可以正常但导出的速度很可怕,我希望导出时间少于5秒,对于4000行计数,怎么能我改进了吗?
谢谢
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
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;
}
推荐答案
尝试
http://weblogs.asp.net/stanleygu/archive/2009/12/ 16 / export-silverlight-datagrid-to-excel-xml.aspx [ ^ ]
将Silverlight DataGrid导出为Excel XML / CSV [ ^ ]
这篇关于导出到Excel的速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文