[英]Most efficient ways of working with large Excel ranges in C#?
I am working with Excel Interop in C# and am writing code to do somewhat complicated manipulation of tables with tens of thousands of rows of data. 我正在使用C#中的Excel Interop,并且正在编写代码来对带有数万行数据的表进行一些复杂的操作。 It tends to run pretty slow.
它往往运行得很慢。
I often have data stored in some kind of variables that I perform some intermediate calculations on before ultimately writing the results to a worksheet. 我经常将数据存储在某种变量中,在最终将结果写入工作表之前,我会执行一些中间计算。
I am sure this is not a good approach, but I frequently find myself building a temporary worksheet that will be deleted when my code is finished executing, so that I can use Excel methods of the Range property on the data rather than trying to implement similar methods in an array. 我确信这不是一个好方法,但我经常发现自己构建了一个临时工作表,当我的代码执行完毕后将被删除,这样我就可以在数据上使用Range属性的Excel方法而不是尝试实现类似的数组中的方法。 Most frequently, this involves things like sorting by multiple columns, removing duplicates, etc. These columns almost always have many different types of data (strings, whole numbers, numbers with two decimal places - although the actual data types stored in these cells does not seem to always be straightforward (100000000.01 for example seems to sometimes be of type double and other times be decimal). The easiest way to deal with all of the different data types seems to be just using an Excel range, and this is why my code is frequently creating temporary worksheets, then deleting them in my code.
最常见的是,这涉及诸如按多列排序,删除重复项等内容。这些列几乎总是有许多不同类型的数据(字符串,整数,带有两个小数位的数字 - 尽管存储在这些单元格中的实际数据类型不是似乎总是很简单(例如,100000000.01似乎有时是double类型,其他时候是十进制)。处理所有不同数据类型的最简单方法似乎只是使用Excel范围,这就是为什么我的代码经常创建临时工作表,然后在我的代码中删除它们。
What is the proper, efficient way to deal with these types of situations? 处理这些类型情况的正确,有效方法是什么?
Take a look at these links 看看这些链接
If you are updating individual cells that is going to be very slow. 如果要更新速度非常慢的单个单元格。 But in general, excel interop is slow.
但总的来说,excel互操作很慢。 Have you considered maybe creating a CSV file, and then using excel interop to convert the final result?
您是否考虑过创建CSV文件,然后使用excel interop转换最终结果?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.