简体   繁体   English

使用 c# 中的 Excel 互操作从多个.xlsx 文件中提取数据的最有效方法?

[英]Most efficient way to extract data from multiple .xlsx files using Excel Interop in c#?

I have just started getting into Excel Interop and was wondering how I could improve the performance of my application by implementing either multithreading or multitasking.我刚刚开始接触 Excel Interop,想知道如何通过实现多线程或多任务来提高应用程序的性能。

My code looks something like this atm:我的代码看起来像这样的ATM:

foreach(var path in arrayOfExcelFilePaths){
    excelApp.Workbooks.Open(path);
}
foreach(var wb in excelApp.Workbooks){
    //Read stuff and maybe write stuff
}

Thanks in advance for anybody looking into this.提前感谢任何对此进行调查的人。

Using Interop is a bad idea in general.一般来说,使用互操作是一个坏主意。 The execution of your code won't differ much from its equivalent written in a VBA macro, because Interop simply runs the Excel process in the background and replicates its functionality 1-to-1.您的代码的执行与在 VBA 宏中编写的等效代码没有太大区别,因为 Interop 只是在后台运行 Excel 进程并一对一地复制其功能。

Try OfficeOpenXML or any other library that allows you manipulate the content of excel sheets without running MS Excel as Interop does.尝试使用 OfficeOpenXML 或任何其他允许您操作 excel 工作表内容的库,而无需像 Interop 那样运行 MS Excel。

I highly recommend you use the EPPlus 5 library, which is a newer version of the EPPlus library.我强烈建议您使用EPPlus 5库,它是EPPlus库的更新版本。 Its fast and reliable, I've been using it for years without any issues.它快速可靠,我多年来一直在使用它,没有任何问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将数据从 C++ 传递到 C# 的最有效方法 - Most efficient way to pass data from C++ to C# 对多个Excel工作簿中的记录进行排序-C#Excel Interop - Sorting records from multiple excel workbooks - C# Excel Interop 使用索引从列表中提取多个(非连续)值的最紧凑和/或最有效的方法是什么 - What is the most compact and/or efficient way to extract multiple (non-consecutive) values from a list using indexing 在C#中将大型双精度数组保存为文件的最有效方法 - Most efficient way to save large double arrays as files in C# 从C#编写Excel的有效方法 - Efficient way to write excel from C# 使用C#查找磁盘上所有exe文件的最有效方法? - Most efficient way to find all exe files on disk using C#? 在C#中比较多组数据重叠的最有效方法是什么 - What is the most efficient way to compare multiple sets of data for overlaps in C# C#-遍历多个数组/列表的最有效方法 - C# - Most efficient way to iterate through multiple arrays/list C# COM Interop Excel:如何使用 Interop Excel 从 C# 写入单元格? - C# COM Interop Excel: How to write to cells from C# using Interop Excel? C#如何使用Interop从Excel读取和写入数据,而不显示Excel? - C# How to read and write data from Excel using Interop, without making Excel visible?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM