Get External Connection Data Source of Pivot Table
Contents
[
Hide
]
How to Get External Connection Data Source of Pivot Table
Aspose.Cells for JavaScript via C++ 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 externalConnectionDataSourceproperty returns the ExternalConnection object. The following code snippet demonstrates the use of the externalConnectionDataSource property to get the external connection data source of the pivot table.
Sample Code
<!DOCTYPE html>
<html>
<head>
<title>Pivot Table External Connection Example</title>
</head>
<body>
<h1>Pivot Table External Connection Example</h1>
<input type="file" id="fileInput" accept=".xls,.xlsx,.csv" />
<button id="runExample">Run Example</button>
<a id="downloadLink" style="display: none;">Download Result</a>
<div id="result"></div>
</body>
<script src="aspose.cells.js.min.js"></script>
<script type="text/javascript">
const { Workbook, SaveFormat, Utils } = AsposeCells;
AsposeCells.onReady({
license: "/lic/aspose.cells.enc",
fontPath: "/fonts/",
fontList: [
"arial.ttf",
"NotoSansSC-Regular.ttf"
]
}).then(() => {
console.log("Aspose.Cells initialized");
});
document.getElementById('runExample').addEventListener('click', async () => {
const fileInput = document.getElementById('fileInput');
const resultDiv = document.getElementById('result');
if (!fileInput.files.length) {
resultDiv.innerHTML = '<p style="color: red;">Please select an Excel file.</p>';
return;
}
const file = fileInput.files[0];
const arrayBuffer = await file.arrayBuffer();
// Instantiating a Workbook object by opening the selected Excel file
const workbook = new Workbook(new Uint8Array(arrayBuffer));
// Accessing the first worksheet in the Excel file
const worksheet = workbook.worksheets.get(0);
// Get the pivot table
const pivotTable = worksheet.pivotTables.get(0);
// Get external connection data source
const externalConnection = pivotTable.externalConnectionDataSource;
const name = externalConnection.name;
const type = externalConnection.type;
console.log("External Connection Data Source");
console.log("Name: " + name);
console.log("Type: " + type);
resultDiv.innerHTML = `<p style="color: green;">External Connection Data Source</p>
<p>Name: ${name}</p>
<p>Type: ${type}</p>`;
});
</script>
</html>
The source file used in the code snippet is attached for reference.