我如何加速从C#创建excel Excel电子表格? [英] How can I speed-up creating excel Excel spreadsheets from C#?

查看:100
本文介绍了我如何加速从C#创建excel Excel电子表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用带有C#COM Interop的Excel 2007编写大约200个Excel电子表格。

I am currently writing around 200 Excel spreadsheets using Excel 2007 with C# COM Interop.

不幸的是,我需要大约4分钟的时间写这些200张 - 每张表都有1000行与8- 10列。

Unfortunately I need about 4 minutes to write these 200 sheets - each sheet has around 1000 rows with 8- 10 columns.

如何加快速度?

我的代码看起来像这样基本上:

My code looks like this basically:

var xlApp = new Excel.Application();
xlApp.DisplayAlerts=false;
foreach (x in z) {
   var wb = xlApp.Workbooks.add(XLWBATemplae.xlWBATWorksheet);
   var ws = (Worksheet)wb.Worksheets[1];
   //fill data into sheet
   wb.SaveAs(fileName);
   wbClose();
}

澄清:我正在单独填充每个单元格

clarification:I am filling every cell individually right now

我会尝试一些您的建议,然后接受最佳解决方案。

I will try out some of the suggestions from you and will then accept the best solution.

推荐答案

p>您可以通过使用EPPlus (此处)来完全摆脱COM Interop。该库通过使用2007 XML格式而不是Excel COM接口创建Excel文件,结果更快。

You can get rid of COM Interop altogether, by using EPPlus (here). This library creates Excel files by using the 2007 XML format, not the Excel COM interface, and is a lot quicker as a result.

这篇关于我如何加速从C#创建excel Excel电子表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆