简体   繁体   English

Excel Interop - 快速应用单元格颜色

[英]Excel Interop - Quickly Applying Cell Color

I have a large array full of ole color values that I need to apply to cells in an excel worksheet.我有一个充满 ole 颜色值的大数组,我需要将其应用于 Excel 工作表中的单元格。

They could be applied with a simple for loop.它们可以通过一个简单的 for 循环来应用。 pseudo code:伪代码:

 for (int k = 0; k < oleColorArray.Count; k++){
   worksheet.Cells[1, k].Interior.Color = oleColorArray[k];
 }

However this approach is slow, even after disabling ScreenUpdating.然而,这种方法很慢,即使在禁用 ScreenUpdating 之后也是如此。 I've got around 1500 entries and it can take up to a minute.我有大约 1500 个条目,最多可能需要一分钟。

Since the values in the array are all different I can't color the whole range.由于数组中的值都不同,我无法为整个范围着色。

I've seen that cell values can be applied directly from a 2D array using我已经看到可以使用直接从二维数组应用单元格值

range.set_Value(); or range.Value()

Microsoft.Office.Interop.Excel really slow Microsoft.Office.Interop.Excel 真的很慢

Is there any similar way to apply an array of ole colors, if not is there a faster approach I am missing?是否有任何类似的方法来应用一系列 ole 颜色,如果没有,我是否缺少一种更快的方法?

Have you tried using the conditional formatting options function instead of using VBA coding?您是否尝试过使用条件格式选项功能而不是使用 VBA 编码? Any reason why you are unable to use conditional formatting and are forced to use VBA?您无法使用条件格式并被迫使用 VBA 的任何原因?

Conditional Formatting can be set up so its logic is built off of one cell or a range and can apply to the ranges you are looking to color code.可以设置条件格式,使其逻辑建立在一个单元格或一个范围之外,并且可以应用于您正在寻找颜色代码的范围。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM