الحصول على النطاقات المرتبطة بالمصادر الخارجية باستخدام JavaScript عبر C++
Contents
[
Hide
]
الحصول على نطاق مع روابط خارجية
غالبًا ما تصل ملفات Excel إلى البيانات من ملفات Excel أخرى باستخدام روابط خارجية. يوفر Aspose.Cells for JavaScript عبر C++ خيار استرجاع هذه الروابط الخارجية باستخدام طريقة Name.referredAreas(boolean). تعيد طريقة Name.referredAreas(boolean) مصفوفة من النوع ReferredArea. يوفر فصل ReferredArea خاصية ReferredArea.externalFileName التي تعيد اسم الملف الخارجي. يكشف فصل ReferredArea عن الأعضاء التالية.
- ReferredArea.endColumn: عمود النهاية للمنطقة
- ReferredArea.endRow: الصف النهائي للمنطقة
- ReferredArea.externalFileName: الحصول على اسم الملف الخارجي إذا كان هذا مرجع خارجي
- ReferredArea.isArea(): يشير إلى ما إذا كان هذا منطقة
- ReferredArea.isExternalLink(): يشير إلى ما إذا كان هذا ارتباط خارجي
- ReferredArea.sheetName: يشير إلى الورقة التي يقع فيها هذا المرجع
- ReferredArea.startColumn: العمود الابتدائي للمنطقة
- ReferredArea.startRow: صف البداية للمنطقة
يوضح رمز النموذج المقدم أدناه استخدام طريقة Name.referredAreas(boolean) للحصول على النطاقات ذات الروابط الخارجية.
الكود المثالي
<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells Example - External References</title>
</head>
<body>
<h1>Sample External References</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, Worksheet, Cell, 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');
resultDiv.innerHTML = '';
if (!fileInput.files.length) {
resultDiv.innerHTML = '<p style="color: red;">Please select an Excel file (SampleExternalReferences.xlsx).</p>';
return;
}
const file = fileInput.files[0];
const arrayBuffer = await file.arrayBuffer();
// Instantiating a Workbook object from the uploaded file
const workbook = new Workbook(new Uint8Array(arrayBuffer));
// Accessing named ranges via worksheets.names
const names = workbook.worksheets.names;
const namesCount = names.count;
const outputLines = [];
outputLines.push(`<p>Processing file: ${file.name}</p>`);
outputLines.push(`<p>Named Ranges Count: ${namesCount}</p>`);
for (let i = 0; i < namesCount; i++) {
const namedRange = names.get(i);
outputLines.push(`<h3>Named Range ${i}: ${namedRange.name || ('Index ' + i)}</h3>`);
// Get referred areas (including external references)
const referredAreas = namedRange.referredAreas(true);
if (referredAreas) {
referredAreas.forEach((referredArea, idx) => {
outputLines.push(`<h4>Referred Area ${idx}</h4>`);
outputLines.push(`<ul>`);
outputLines.push(`<li>IsExternalLink: ${referredArea.isExternalLink}</li>`);
outputLines.push(`<li>IsArea: ${referredArea.isArea}</li>`);
outputLines.push(`<li>SheetName: ${referredArea.sheetName}</li>`);
outputLines.push(`<li>ExternalFileName: ${referredArea.externalFileName}</li>`);
outputLines.push(`<li>StartColumn: ${referredArea.startColumn}</li>`);
outputLines.push(`<li>StartRow: ${referredArea.startRow}</li>`);
outputLines.push(`<li>EndColumn: ${referredArea.endColumn}</li>`);
outputLines.push(`<li>EndRow: ${referredArea.endRow}</li>`);
outputLines.push(`</ul>`);
});
} else {
outputLines.push(`<p>No referred areas for this named range.</p>`);
}
}
resultDiv.innerHTML = outputLines.join('');
});
</script>
</html>