简体   繁体   中英

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.

They could be applied with a simple for loop. 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. I've got around 1500 entries and it can take up to a minute.

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

Is there any similar way to apply an array of ole colors, if not is there a faster approach I am missing?

Have you tried using the conditional formatting options function instead of using VBA coding? Any reason why you are unable to use conditional formatting and are forced to use 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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