إدارة القوائم النقطية والمرقمة في العروض التقديمية باستخدام JavaScript
نظرة عامة
Aspose.Slides لـ Node.js عبر Java يتيح لك إنشاء وتنسيق القوائم ذات النقاط والرقم في عروض PowerPoint وOpenDocument. عنصر القائمة هو فقرة يتم التحكم في إعدادات النقطة الخاصة بها من خلال تنسيق الفقرة.
استخدم الفئة Paragraph للوصول إلى إعدادات القائمة على مستوى الفقرة. نقطة الدخول الرئيسية هي Paragraph.getParagraphFormat().getBullet()، التي تُرجع كائنًا من نوع BulletFormat. باستخدام هذا الكائن، يمكنك تعيين نوع النقطة، الرمز، الصورة، اللون، الحجم، نمط الترقيم، ورقم البدء.
يظهر هذا المقال كيف:
- إنشاء قائمة نقطية برمز مخصص
- إنشاء نقطة صورة
- إنشاء قائمة متعددة المستويات عن طريق ضبط عمق الفقرة
- إنشاء قائمة مرقمة
- فحص وتعديل تنسيق القائمة في عرض تقديمي موجود
- قراءة العلامات الفعلية للقائمة والأرقام بجانب نص الفقرة
إنشاء قائمة نقطية
لإنشاء قائمة نقطية، أضف كائنات Paragraph إلى TextFrame واضبط BulletFormat.setType على BulletType.Symbol. يمكنك بعد ذلك تعيين BulletFormat.setChar و BulletFormat.getColor و BulletFormat.setHeight للتحكم في مظهر النقطة.
يعرض كود JavaScript التالي كيفية إنشاء قائمة نقطية في شريحة:
var aspose = aspose || {};
aspose.slides = require("aspose.slides.via.java");
const java = require("java");
function createParagraph(text, bulletColor) {
const paragraph = new aspose.slides.Paragraph();
const paragraphFormat = paragraph.getParagraphFormat();
const bulletFormat = paragraphFormat.getBullet();
bulletFormat.setType(java.newByte(aspose.slides.BulletType.Symbol));
bulletFormat.setChar(java.newChar("*"));
paragraphFormat.setIndent(15);
bulletFormat.setBulletHardColor(java.newByte(aspose.slides.NullableBool.True));
bulletFormat.getColor().setColor(bulletColor);
bulletFormat.setHeight(100);
paragraph.setText(text);
return paragraph;
}
const presentation = new aspose.slides.Presentation();
try {
const slide = presentation.getSlides().get_Item(0);
const autoShape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 20, 20, 200, 50);
const textFrame = autoShape.getTextFrame();
textFrame.getParagraphs().clear();
const bulletColor = java.newInstanceSync("java.awt.Color", 205, 92, 92);
const paragraph1 = createParagraph("The first paragraph", bulletColor);
textFrame.getParagraphs().add(paragraph1);
const paragraph2 = createParagraph("The second paragraph", bulletColor);
textFrame.getParagraphs().add(paragraph2);
presentation.save("symbol_bullets.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
النتيجة:

إنشاء قائمة مرقمة
استخدم القوائم المرقمة عندما يكون ترتيب العناصر مهمًا. اضبط BulletFormat.setType على BulletType.Numbered. يمكنك أيضًا اختيار تنسيق الترقيم باستخدام BulletFormat.setNumberedBulletStyle أو ضبط BulletFormat.setNumberedBulletStartWith عندما يجب أن تبدأ القائمة من قيمة غير 1.
يعرض كود JavaScript التالي كيفية إنشاء قائمة مرقمة في شريحة:
var aspose = aspose || {};
aspose.slides = require("aspose.slides.via.java");
const java = require("java");
const presentation = new aspose.slides.Presentation();
try {
const slide = presentation.getSlides().get_Item(0);
const autoShape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 20, 20, 90, 80);
const textFrame = autoShape.getTextFrame();
textFrame.getParagraphs().clear();
const paragraph1 = new aspose.slides.Paragraph();
paragraph1.getParagraphFormat().getBullet().setType(java.newByte(aspose.slides.BulletType.Numbered));
paragraph1.setText("Apple");
textFrame.getParagraphs().add(paragraph1);
const paragraph2 = new aspose.slides.Paragraph();
paragraph2.getParagraphFormat().getBullet().setType(java.newByte(aspose.slides.BulletType.Numbered));
paragraph2.setText("Orange");
textFrame.getParagraphs().add(paragraph2);
const paragraph3 = new aspose.slides.Paragraph();
paragraph3.getParagraphFormat().getBullet().setType(java.newByte(aspose.slides.BulletType.Numbered));
paragraph3.setText("Banana");
textFrame.getParagraphs().add(paragraph3);
presentation.save("numbered_bullets.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
النتيجة:

إنشاء نقطة صورة
يسمح Aspose.Slides لك باستبدال رمز النقطة العادي بصورة. تعمل نقاط الصورة بشكل أفضل مع صور بسيطة تظل مقروءة بحجم صغير، مثل الأيقونات أو ملفات PNG الشفافة الصغيرة.
Note
من المثالي، إذا كنت تخطط لاستبدال رمز النقطة العادي بصورة، يفضل اختيار رسم بسيط بخلفية شفافة. مثل هذه الصور تعمل جيدًا كرموز نقطية مخصصة.
ضع في اعتبارك أن الصورة سيتم تصغيرها إلى حجم صغير جدًا. لهذا السبب، نوصي بشدة باختيار صورة تظل واضحة وفعّالة بصريًا عند استخدامها كنقطة في قائمة.
لإنشاء نقطة صورة، أضف صورة إلى Presentation باستخدام Presentation.getImages().addImage وعيّن الكائن PPImage المُرجع إلى BulletFormat.getPicture().setImage. اضبط BulletFormat.setType على BulletType.Picture قبل تعيين الصورة.
لنفترض أن لدينا ملف “image.png”:

var aspose = aspose || {};
aspose.slides = require("aspose.slides.via.java");
const java = require("java");
function createParagraph(text, image) {
const paragraph = new aspose.slides.Paragraph();
const paragraphFormat = paragraph.getParagraphFormat();
const bulletFormat = paragraphFormat.getBullet();
bulletFormat.setType(java.newByte(aspose.slides.BulletType.Picture));
bulletFormat.getPicture().setImage(image);
paragraphFormat.setIndent(15);
bulletFormat.setHeight(100);
paragraph.setText(text);
return paragraph;
}
const presentation = new aspose.slides.Presentation();
let image = null;
try {
const slide = presentation.getSlides().get_Item(0);
const autoShape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 20, 20, 200, 50);
const textFrame = autoShape.getTextFrame();
textFrame.getParagraphs().clear();
image = aspose.slides.Images.fromFile("image.png");
const bulletImage = presentation.getImages().addImage(image);
const paragraph1 = createParagraph("The first paragraph", bulletImage);
textFrame.getParagraphs().add(paragraph1);
const paragraph2 = createParagraph("The second paragraph", bulletImage);
textFrame.getParagraphs().add(paragraph2);
presentation.save("picture_bullets.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
if (image !== null) {
image.dispose();
}
presentation.dispose();
}
النتيجة:

إنشاء قائمة متعددة المستويات
استخدم ParagraphFormat.setDepth لوضع عناصر القائمة في مستويات مختلفة. المستوى 0 هو المستوى العلوي، المستوى 1 متداخل تحته، وهكذا.
الكود التالي في JavaScript يوضح كيفية إنشاء قائمة نقطية متعددة المستويات:
var aspose = aspose || {};
aspose.slides = require("aspose.slides.via.java");
const java = require("java");
const presentation = new aspose.slides.Presentation();
try {
const slide = presentation.getSlides().get_Item(0);
const autoShape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 20, 20, 260, 110);
const textFrame = autoShape.getTextFrame();
textFrame.getParagraphs().clear();
const paragraph1 = new aspose.slides.Paragraph();
paragraph1.getParagraphFormat().setDepth(java.newShort(0));
paragraph1.setText("My text - Depth 0");
textFrame.getParagraphs().add(paragraph1);
const paragraph2 = new aspose.slides.Paragraph();
paragraph2.getParagraphFormat().setDepth(java.newShort(1));
paragraph2.setText("My text - Depth 1");
textFrame.getParagraphs().add(paragraph2);
const paragraph3 = new aspose.slides.Paragraph();
paragraph3.getParagraphFormat().setDepth(java.newShort(2));
paragraph3.setText("My text - Depth 2");
textFrame.getParagraphs().add(paragraph3);
const paragraph4 = new aspose.slides.Paragraph();
paragraph4.getParagraphFormat().setDepth(java.newShort(3));
paragraph4.setText("My text - Depth 3");
textFrame.getParagraphs().add(paragraph4);
presentation.save("multilevel_bullets.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
النتيجة:

تعديل قائمة موجودة
لتغيير تنسيق القائمة في عرض تقديمي موجود، احصل على الفقرة المستهدفة وقم بتحديث إعدادات ParagraphFormat.getBullet الخاصة بها. يمكن استخدام نفس الخصائص المستخدمة لإنشاء القوائم لفحص أو تعديل القوائم التي تم تحميلها من ملف PPT أو PPTX أو ODP.
var aspose = aspose || {};
aspose.slides = require("aspose.slides.via.java");
const java = require("java");
const presentation = new aspose.slides.Presentation("input.pptx");
try {
const slide = presentation.getSlides().get_Item(0);
const autoShape = slide.getShapes().get_Item(0);
const paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
const paragraphFormat = paragraph.getParagraphFormat();
const bulletFormat = paragraphFormat.getBullet();
bulletFormat.setType(java.newByte(aspose.slides.BulletType.Numbered));
bulletFormat.setNumberedBulletStyle(java.newByte(aspose.slides.NumberedBulletStyle.BulletRomanUCPeriod));
bulletFormat.setNumberedBulletStartWith(java.newShort(1));
paragraphFormat.setMarginLeft(30);
paragraphFormat.setIndent(-20);
presentation.save("updated_list.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
قراءة قيم النقاط الفعلية
عند استخراج محتوى العرض التقديمي، احتفظ بعلامات القوائم إلى جانب نص الفقرة. استدعِ ParagraphFormat.getEffective والوصول إلى IParagraphFormatEffectiveData.getBullet للحصول على تنسيق النقطة الفعلي. تحقق من getType قبل قراءة getActualBulletValue.
للقوائم المرقمة، ميز هذه القيم الثلاث:
- getNumberedBulletStyle يحدد التنسيق، مثل الأرقام العربية متبوعة بنقطة أو الحروف الصغيرة متبوعة بنقطة.
- getNumberedBulletStartWith يحدد رقم البداية لمجموعة من الفقرات المرقمة.
- getActualBulletValue يُرجع العلامة المُنسقة لفقرة معينة. على سبيل المثال، العنصر الثاني في قائمة تبدأ من 5 يُرجع
6..
احتفظ بـ getDepth لكل فقرة للاحتفاظ بمستوى التداخل الخاص بها. العلامة الفعلية لا تُشفّر الهرمية الكاملة: يمكن لعنصر متداخل إرجاع c. بدلاً من تسمية مركبة مثل 6.c..
يُظهر المثال التالي المستقل كيفية إنشاء القوائم، حفظها في عرض تقديمي، وإعادة تحميل العرض لتقرير نص كل فقرة، العمق، نوع النقطة، والقيمة الفعلية. يتم إنشاء علامة الصورة الزرقاء الصغيرة من SVG مضمّن.
var aspose = aspose || {};
aspose.slides = require("aspose.slides.via.java");
const java = require("java");
const black = java.newInstanceSync("java.awt.Color", 0, 0, 0);
const presentation = new aspose.slides.Presentation();
try {
presentation.getSlideSize().setSize(720, 440, aspose.slides.SlideSizeScaleType.DoNotScale);
const slide = presentation.getSlides().get_Item(0);
const shape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 30, 20, 660, 400);
shape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.NoFill));
shape.getLineFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.NoFill));
const textFrame = shape.getTextFrame();
textFrame.getParagraphs().clear();
// إنشاء علامة صورة بدون ملف صورة خارجي.
const svg = new aspose.slides.SvgImage("<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16'><rect width='16' height='16' rx='4' fill='#0078D4'/></svg>");
const bulletImage = presentation.getImages().addImage(svg);
function addParagraph(text, depth, type, start, style) {
const paragraph = new aspose.slides.Paragraph();
paragraph.setText(text);
const format = paragraph.getParagraphFormat();
format.setDepth(java.newShort(depth));
format.setMarginLeft(30 + depth * 40);
format.setIndent(-28);
format.setSpaceAfter(8);
format.getDefaultPortionFormat().setFontHeight(22);
format.getDefaultPortionFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
format.getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(black);
format.getBullet().setType(java.newByte(type));
format.getBullet().setBulletHardColor(java.newByte(aspose.slides.NullableBool.True));
format.getBullet().getColor().setColor(black);
if (type === aspose.slides.BulletType.Numbered) {
format.getBullet().setNumberedBulletStyle(java.newByte(style));
format.getBullet().setNumberedBulletStartWith(java.newShort(start));
} else if (type === aspose.slides.BulletType.Symbol) {
format.getBullet().setChar(java.newChar(0x2022));
} else if (type === aspose.slides.BulletType.Picture) {
format.getBullet().getPicture().setImage(bulletImage);
}
textFrame.getParagraphs().add(paragraph);
}
addParagraph("First item", 0, aspose.slides.BulletType.Numbered, 5, aspose.slides.NumberedBulletStyle.BulletArabicPeriod);
addParagraph("Second item", 0, aspose.slides.BulletType.Numbered, 5, aspose.slides.NumberedBulletStyle.BulletArabicPeriod);
addParagraph("Nested item", 1, aspose.slides.BulletType.Numbered, 3, aspose.slides.NumberedBulletStyle.BulletAlphaLCPeriod);
addParagraph("Next nested item", 1, aspose.slides.BulletType.Numbered, 3, aspose.slides.NumberedBulletStyle.BulletAlphaLCPeriod);
addParagraph("Deep item", 2, aspose.slides.BulletType.Numbered, 4, aspose.slides.NumberedBulletStyle.BulletRomanLCPeriod);
addParagraph("Back to top level", 0, aspose.slides.BulletType.Numbered, 5, aspose.slides.NumberedBulletStyle.BulletArabicPeriod);
addParagraph("Symbol marker", 0, aspose.slides.BulletType.Symbol, 1, aspose.slides.NumberedBulletStyle.BulletArabicPeriod);
addParagraph("No bullet", 0, aspose.slides.BulletType.None, 1, aspose.slides.NumberedBulletStyle.BulletArabicPeriod);
addParagraph("Picture marker", 0, aspose.slides.BulletType.Picture, 1, aspose.slides.NumberedBulletStyle.BulletArabicPeriod);
presentation.save("actual_bullet_values.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
const loadedPresentation = new aspose.slides.Presentation("actual_bullet_values.pptx");
try {
const loadedShape = loadedPresentation.getSlides().get_Item(0).getShapes().get_Item(0);
console.log("Text | Depth | Type | Actual value");
const paragraphs = loadedShape.getTextFrame().getParagraphs();
for (let i = 0; i < paragraphs.getCount(); i++) {
const paragraph = paragraphs.get_Item(i);
const bullet = paragraph.getParagraphFormat().getEffective().getBullet();
let marker;
switch (bullet.getType()) {
case aspose.slides.BulletType.Numbered:
case aspose.slides.BulletType.Symbol:
marker = bullet.getActualBulletValue();
break;
case aspose.slides.BulletType.None:
marker = bullet.getActualBulletValue() + " (no bullet)";
break;
case aspose.slides.BulletType.Picture:
marker = bullet.getActualBulletValue() + " (image required)";
break;
default:
marker = "unsupported bullet type";
break;
}
const typeName = Object.keys(aspose.slides.BulletType).find(name => aspose.slides.BulletType[name] === bullet.getType());
console.log(paragraph.getText() + " | " + paragraph.getParagraphFormat().getDepth() + " | " + typeName + " | " + marker);
}
} finally {
loadedPresentation.dispose();
}
القوائم المصدرية معروضة أدناه.

Text | Depth | Type | Actual value
First item | 0 | Numbered | 5.
Second item | 0 | Numbered | 6.
Nested item | 1 | Numbered | c.
Next nested item | 1 | Numbered | d.
Deep item | 2 | Numbered | iv.
Back to top level | 0 | Numbered | 7.
Symbol marker | 0 | Symbol | •
No bullet | 0 | None | null (no bullet)
Picture marker | 0 | Picture | null (image required)
بالنسبة إلى BulletType.None وBulletType.Picture، تُرجع getActualBulletValue القيمة null، وليس سلسلة فارغة. يجب التعامل مع هذين النوعين بشكل منفصل: الأول لا يحتوي على علامة، بينما يتطلب الثاني استخراج صورة النقطة بشكل منفصل. لا يمكن إعادة إنشاء نقطة صورة فقط باستخراج علامة نصية.
FAQ
هل يمكن تصدير القوائم النقطية والمرقمة إلى PDF أو صور؟
نعم. يحافظ Aspose.Slides على تنسيق القوائم عندما يدعم تنسيق الهدف تخطيط النص المقابل وميزات النقاط.
هل يمكنني تعديل القوائم في العروض التقديمية الموجودة؟
نعم. قم بتحميل العرض التقديمي، احصل على الفقرة المستهدفة، افحص أو حدّث إعدادات ParagraphFormat.getBullet الخاصة بها، ثم احفظ العرض التقديمي.
هل يمكن للقوائم أن تحتوي على نص غير لاتيني؟
نعم. يمكن أن يحتوي نص عنصر القائمة على أحرف Unicode، لذا يمكنك إنشاء قوائم في عروض تقديمية متعددة اللغات. تأكد من أن الخطوط المستخدمة في العرض تدعم الأحرف التي تحتاجها.