Get External Connection Data Source of Pivot Table

Get External Connection Data Source of Pivot Table

Aspose.Cells provides the ability to get the external connection data source of the pivot table. For this, the API provides the ExternalConnectionDataSource property of the PivotTable class. The ExternalConnectionDataSource property returns the ExternalConnection object. The following code snippet demonstrates the use of the PivotTable.ExternalConnectionDataSource property to get the external connection data source of the pivot table.

Sample Code

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
// Load sample file
Workbook workbook = new Workbook(sourceDir + "SamplePivotTableExternalConnection.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
// Get the pivot table
var pivotTable = worksheet.PivotTables[0];
// Print External Connection Details
Console.WriteLine("External Connection Data Source");
ExternalConnection[] connections = pivotTable.GetSourceDataConnections();
foreach(ExternalConnection conn in connections)
{
Console.WriteLine("Name: " + conn.Name);
Console.WriteLine("Type: " + conn.SourceType);
}

The source file used in the code snippet is attached for reference.

Source File