我遇到了VSTO解決方案的性能問題,我相信其原因主要是cellColor逐個單元格設置的方式。如何將數組從C#(VSTO)項目傳遞到VBA宏
這取決於記錄集中的數據,因此每次都有所不同。 (我不能從另一行/列使用copyFormats)
它類似於填充值的範圍,只爲那個有幾種方法。
我考慮先在存儲器中創建C#中的整個事情(一個XlColorIndex [,]數組),我通過給VBA方法類似於下面的一個:
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
我一直試圖執行這個宏在下面的方法,但都沒有取得成功呢,任何指針是極大的讚賞:
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);
我試過INT [,] -
我沒有得到一個不同的ER ROR當我試圖可空int或double: 雙[,](可空雙陣列):
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
如果我不嘗試空類型,我得到了以下HRESULT錯誤
(類型missmatch?)Exception from HRESULT: 0x800A000D
突然出現類型不匹配發生在我的VBA代碼進入雙ForEach時,這不適用於我從C#傳遞的數組。 – 2009-10-08 04:29:36