I'm having performance issues with my VSTO solution, I believe the reason is mainly the way the cellColor is set cell by cell.
This depends on data from a recordSet and is thus different everytime. (I can't use a copyFormats from another row/column)
it's similar to filling a Range of values, only for that one there are several methods.
I thought about creating the whole thing in C# in Memory first (a XlColorIndex[,] array) which I pass through to a VBA method similar to the one below:
Sub fillInterior(ByRef rg As Range, a As Variant)
//a is a double array that represents the colors for the spreadsheet
Dim r As Long, c As Long
Dim tmpRg As Range
r = 1
c = 1
For Each Row In a
For Each colorIdx In Row
Set tmpRg = rg(r, c)
With tmpRg.Interior
.ColorIndex = colorIdx
.PatternColorIndex = xlAutomatic
.PatternColor = xlSolid
End With
c = c + 1
Next
c = 1
r = r + 1
Next
End Sub
I've been trying to call this Macro in the following way, but haven't been successful yet, any pointers are greatly appreciated:
Excel.Range rg = this.Range[this.Cells[5, 3], this.Cells[6, 4]];
object[,] test2 = new object[2, 2];
test2[0, 0] = 15;
test2[0, 1] = 15;
test2[1, 0] = 15;
test2[1, 1] = 15;
this.Application.Run("Sheet1.fillInterior", rg, test2,
System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing,
System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing,
System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing,
System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing);
I've tried int[,] -
I did get a different error when I tried Nullable int or Double: double?[,] (Array of Nullable Double):
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
If I don't try nullable types I got the following HRESULT error (Type missmatch?)
Exception from HRESULT: 0x800A000D