تعيين الهوامش للتعليق أو الشكل داخل ورقة العمل باستخدام جافا سكريبت عبر C++
Contents
[
Hide
]
سيناريوهات الاستخدام المحتملة
يسمح Aspose.Cells لك بضبط هوامش أي شكل أو تعليق باستخدام خاصية Shape.textBody.textAlignment. تعيد هذه الخاصية كائن من فئة Aspose.Cells.Drawing.Texts.ShapeTextAlignment الذي يحتوي على خصائص مختلفة مثل ShapeTextAlignment.topMarginPt، ShapeTextAlignment.leftMarginPt، ShapeTextAlignment.bottomMarginPt، ShapeTextAlignment.rightMarginPt، وغيرها، والتي يمكن استخدامها لضبط الهوامش العليا، اليسرى، السفلى واليمنى.
تعيين هوامش التعليق أو الشكل داخل ورقة العمل
يرجى الاطلاع على الكود عينة التالي. يقوم بتحميل ملف Excel عيني الذي يحتوي على شكلين. يقوم الكود بالوصول إلى الأشكال واحد تلو الآخر ويضبط هوامشها العلوية واليسرى والسفلية واليمنى. يرجى الاطلاع على ملف Excel الناتج الذي تم إنشاؤه بواسطة الكود ولقطة شاشة توضح تأثير الكود على ملف Excel الناتج.

الكود المثالي
<!DOCTYPE html>
<html>
<head>
<title>Set Margins of Comment or Shape Example</title>
</head>
<body>
<h1>Set Margins of Comment or Shape Inside The Worksheet</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');
if (!fileInput.files.length) {
document.getElementById('result').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);
const shapes = ws.shapes;
for (let i = 0; i < shapes.count; i++) {
const sh = shapes.get(i);
// Access the text alignment
const txtAlign = sh.textBody.textAlignment;
// Set auto margin false
txtAlign.isAutoMargin = false;
// Set the top, left, bottom and right margins
txtAlign.topMarginPt = 10;
txtAlign.leftMarginPt = 10;
txtAlign.bottomMarginPt = 10;
txtAlign.rightMarginPt = 10;
}
// Saving the modified Excel file
const outputData = workbook.save(SaveFormat.Xlsx);
const blob = new Blob([outputData]);
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = 'outputSetMarginsOfCommentOrShapeInsideTheWorksheet.xlsx';
downloadLink.style.display = 'block';
downloadLink.textContent = 'Download Excel File';
document.getElementById('result').innerHTML = '<p style="color: green;">Margins updated successfully! Click the download link to get the modified file.</p>';
});
</script>
</html>