WorksheetBase.ConsolidationSources 屬性
取得字串的 Array,這些字串是用來命名工作表目前彙總的原始工作表和範圍。
命名空間: Microsoft.Office.Tools.Excel
組件: Microsoft.Office.Tools.Excel.v4.0.Utilities (在 Microsoft.Office.Tools.Excel.v4.0.Utilities.dll 中)
語法
'宣告
Public ReadOnly Property ConsolidationSources As Object
Get
public Object ConsolidationSources { get; }
屬性值
型別:System.Object
字串值的 Array,該字串值是用以命名工作表目前彙總的原始工作表和範圍,如果工作表上沒有彙總,則為 nullNull 參照 (即 Visual Basic 中的 Nothing)。
範例
下列程式碼範例會在目前工作表上建立彙總,然後使用 ConsolidationSources 屬性顯示彙總的來源。
這是示範文件層級自訂的範例。
Private Sub ShowConsolidationSources()
' Popluate the data to be consolidated.
Me.Range("A1").Value2 = 22
Me.Range("A2").Value2 = 33
Dim sourceStrings() As String = {"Sheet1!R1C1", _
"Sheet1!R2C1"}
' Consoldate the data by adding it together.
Me.Range("A3").Consolidate( _
sourceStrings, Excel.XlConsolidationFunction.xlSum, _
False, False, False)
' Display the sources of the consolidated data.
If Not (Me.ConsolidationSources Is Nothing) Then
Me.Range("C1").Value2 = _
"Consolidation Sources"
Dim sources As Array = CType(Me.ConsolidationSources, Array)
If sources.Length <> 0 Then
Dim i As Integer
For i = 1 To sources.Length
Me.Range("C" & (i + 1).ToString()).Value2 = sources.GetValue(i)
Next i
Else
Me.Range("C2").Value2 = "None"
End If
Else
MsgBox("This worksheet has no consolidation.")
End If
End Sub
private void ShowConsolidationSources()
{
// Popluate the data to be consolidated.
this.Range["A1", missing].Value2 = 22;
this.Range["A2", missing].Value2 = 33;
string[] sourceStrings = new string[] { "Sheet1!R1C1",
"Sheet1!R2C1" };
// Consoldate the data by adding it together.
this.Range["A3", missing].Consolidate(sourceStrings,
Excel.XlConsolidationFunction.xlSum, false, false, false);
// Display the sources of the consolidated data.
if (this.ConsolidationSources != null)
{
this.Range["C1", missing].Value2 = "Consolidation Sources";
Array sources = (Array)this.ConsolidationSources;
if (sources.Length != 0)
{
for (int i = 1; i <= sources.Length; i++)
{
this.Range["C" + (i + 1).ToString(),
missing].Value2 = sources.GetValue(i);
}
}
else
{
this.Range["C2", missing].Value2 = "None";
}
}
else
{
MessageBox.Show("This worksheet has no consolidation.");
}
}
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。