Excel Interop: Fastest way to change color of portions of text in a huge range of cells

Posted by Kyopaxa on Stack Overflow See other posts from Stack Overflow or by Kyopaxa
Published on 2012-06-30T04:18:47Z Indexed on 2012/07/01 3:16 UTC
Read the original article Hit count: 101

Filed under:
|
|

There some articles about the fastest way to write data using Excel interop assigning directly an Array of data to the value of the range. Like:

string[,] multidimensionalArrayData = new string[200, 3];
    // (...) Fill multidimensionalArrayData with your data
dataSheet.Range["A1:C200"].Value = multidimensionalArrayData;

There are also some articles about how to change the Font color of a specific portion of text, for example (VB this time):

With ActiveCell.Characters(Start:=3, Length:=3).Font
    .Name = "Arial"
    .FontStyle = "Regular"
    .Size = 10
    .Color = "Red"
    .ThemeFont = xlThemeFontNone
End With

The question now is, what would be the fastest way to change the color of specific portions of text for thousands of cells? Currently, in my C# code, I have to do it cell by cell, with a horrible performance hit. Is there a way to fill an array of 'Characters' objects in C# and pass that array to a range in one go? Any other solutions?

© Stack Overflow or respective owner

Related posts about c#

Related posts about excel