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
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"].Value2 = 22;
this.Range["A2"].Value2 = 33;
string[] sourceStrings = new string[] { "Sheet1!R1C1",
"Sheet1!R2C1" };
// Consoldate the data by adding it together.
this.Range["A3"].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()].Value2 = sources.GetValue(i);
}
}
else
{
this.Range["C2", missing].Value2 = "None";
}
}
else
{
MessageBox.Show("This worksheet has no consolidation.");
}
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。