简体   繁体   English

在C#中使用大型Excel范围的最有效方法?

[英]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 看看这些链接

  1. http://www.clear-lines.com/blog/post/Write-data-to-an-Excel-worksheet-with-C-fast.aspx http://www.clear-lines.com/blog/post/Write-data-to-an-Excel-worksheet-with-C-fast.aspx
  2. Excel Interop - Efficiency and performance Excel Interop - 效率和性能
  3. http://xldennis.wordpress.com/2012/01/30/best-practices-export-data-to-excel/ http://xldennis.wordpress.com/2012/01/30/best-practices-export-data-to-excel/

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.

相关问题 处理C#中大型数据数组的最有效方法? - Most efficient way to handle large arrays of data in C#? 在C#中将大型双精度数组保存为文件的最有效方法 - Most efficient way to save large double arrays as files in C# C#处理具有大数据的Excel文件 - c# working on excel files with large data 使用C#和Linq查询海量数据的最有效方法 - Most efficient way to query a large amount of data using C# and Linq C#中解析大型Xml字符串的最有效方法(扩展DTD引用,添加新行等) - most efficient way in c# to parse a large Xml string (to expand DTD references, add new lines etc) C#中处理大量图像文件的最快或最有效方法 - fastest or most efficient way to process large number of image files in c# 使用 c# 中的 Excel 互操作从多个.xlsx 文件中提取数据的最有效方法? - Most efficient way to extract data from multiple .xlsx files using Excel Interop in c#? 将大量数据导出到Excel的最有效方法 - The most efficient way to export large amount of data to excel C#(轮播)中最有效的无限循环 - Most efficient endless loop in C# (carousel) 查询集合的最有效方法-C# - most efficient way to query a collection - c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM