다음을 통해 공유


WorksheetBase.ConsolidationSources Property

Definition

Gets an Array of strings that name the source sheets and ranges for the worksheet's current consolidation.

public:
 property System::Object ^ ConsolidationSources { System::Object ^ get(); };
public object ConsolidationSources { get; }
member this.ConsolidationSources : obj
Public ReadOnly Property ConsolidationSources As Object

Property Value

An Array of string values that name the source sheets and ranges for the worksheet's current consolidation; null if there is no consolidation on the sheet.

Examples

The following code example creates a consolidation on the current worksheet, and then uses the ConsolidationSources property to display the sources of the consolidation.

This example is for a document-level customization.

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.");
    }
}
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

Applies to