استخراج النص من شكل ذكي من نوع Gear باستخدام جافا سكريبت عبر C++
Contents
[
Hide
]
سيناريوهات الاستخدام المحتملة
يمكن لـ Aspose.Cells استخراج النص من شكل ذكي من نوع Gear. للقيام بذلك، يجب أولاً تحويل الشكل الذكي إلى شكل مجموعة باستخدام خاصية Shape.resultOfSmartArt. ثم يجب الحصول على مصفوفة جميع الأشكال الفردية التي تكوّن المجموعة باستخدام الخاصية GroupShape.groupedShapes. أخيرًا، يمكنك التكرار عبر جميع الأشكال الفردية واحدة تلو الأخرى في حلقة واستخراج نصها باستخدام الخاصية Shape.text.
استخراج النص من شكل SmartArt نوع الحركة
يحمل الكود العيني التالي ملف Excel العيني الذي يحتوي على شكل Smart Art Shape من نوع العتاد. ثم يستخرج النص من الأشكال الفردية له كما هو موضح أعلاه. يرجى الاطلاع على مخرجات الوحدة المعطاة أدناه كمرجع.
الكود المثالي
<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells Example</title>
</head>
<body>
<h1>Extract Gear SmartArt Text 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, 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 by opening the Excel file through the file stream
const workbook = new Workbook(new Uint8Array(arrayBuffer));
// Access first worksheet.
const worksheet = workbook.worksheets.get(0);
// Access first shape.
const shape = worksheet.shapes.get(0);
// Get the result of gear type smart art shape in the form of group shape.
const groupShape = shape.resultOfSmartArt;
// Get the list of individual shapes consisting of group shape.
const shapes = groupShape.groupedShapes;
// Extract the text of gear type shapes and display them.
const results = [];
for (let i = 0; i < shapes.count; i++) {
const s = shapes.get(i);
if (s.type === AsposeCells.AutoShapeType.Gear9 || s.type === AsposeCells.AutoShapeType.Gear6) {
const text = s.text;
results.push(text);
console.log("Gear Type Shape Text: " + text);
}
}
if (results.length) {
document.getElementById('result').innerHTML = '<p style="color: green;">Found gear shape texts:</p><ul>' + results.map(t => '<li>' + t + '</li>').join('') + '</ul>';
} else {
document.getElementById('result').innerHTML = '<p style="color: orange;">No gear type SmartArt shapes found in the first shape.</p>';
}
});
</script>
</html>
مخرجات الوحدة
Gear Type Shape Text: Nice
Gear Type Shape Text: Good
Gear Type Shape Text: Excellent