استفد من خاصية Sheet.SheetId في OpenXml باستخدام Aspose.Cells for JavaScript عبر C++
Contents
[
Hide
]
سيناريوهات الاستخدام المحتملة
خاصية Sheet.SheetId متاحة داخل وحدة DocumentFormat.OpenXml.Spreadsheet وهي جزء من OpenXml. يمكنك رؤية هذه الخاصية وقيمتها داخل workbook.xml كما هو موضح في لقطة الشاشة التالية. توفر Aspose.Cells الخاصية المعادلة Worksheet.tabId.

استخدم خاصية Sheet.SheetId من OpenXml باستخدام Aspose.Cells for JavaScript عبر C++
يقوم الكود البرمجي العيني التالي بتحميل ملف Excel عيني، يقرأ تعريف معرف ورقتها أو تبويبها، ثم يعين له معرف تبويب جديد ويحفظه كملف Excel الناتج. يرجى أيضاً النظر إلى مخرجات الكونسول المعروضة في الكود أدناه للإشارة.
الكود المثالي
<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells Example</title>
</head>
<body>
<h1>Sheet Id 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 from the uploaded file
const workbook = new Workbook(new Uint8Array(arrayBuffer));
// Access first worksheet
const ws = workbook.worksheets.get(0);
// Print its Sheet or Tab Id on console and show in page
console.log("Sheet or Tab Id: " + ws.tabId);
resultDiv.innerHTML = `<p>Original Sheet or Tab Id: ${ws.tabId}</p>`;
// Change Sheet or Tab Id
ws.tabId = 358;
// Save the workbook
const outputData = workbook.save(SaveFormat.Xlsx);
const blob = new Blob([outputData]);
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = 'outputSheetId.xlsx';
downloadLink.style.display = 'block';
downloadLink.textContent = 'Download Modified Excel File';
resultDiv.innerHTML += `<p style="color: green;">Sheet Id changed to ${ws.tabId}. Click the download link to get the modified file.</p>`;
});
</script>
</html>
مخرجات الوحدة
Sheet or Tab Id: 1297