Dela via


WorksheetBase.ConsolidationSources Property

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

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

Syntax

'Declaration
Public ReadOnly Property ConsolidationSources As Object
    Get
public Object ConsolidationSources { get; }

Property Value

Type: System.Object
An Array of string values that name the source sheets and ranges for the worksheet's current consolidation; nulla null reference (Nothing in Visual Basic) 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 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 Security

See Also

Reference

WorksheetBase Class

Microsoft.Office.Tools.Excel Namespace