إدارة جداول العروض التقديمية على Android
الجدول في PowerPoint طريقة فعّالة لعرض وتصور المعلومات. المعلومات في شبكة من الخلايا (المرتبة في صفوف وأعمدة) واضحة وسهلة الفهم.
توفر Aspose.Slides الفئة Table والواجهة ITable والفئة Cell والواجهة ICell وأنواع أخرى لتتيح لك إنشاء وتحديث وإدارة الجداول في جميع أنواع العروض التقديمية.
إنشاء جدول من الصفر
- إنشاء مثيل من الفئة Presentation.
- الحصول على مرجع الشريحة عبر الفهرس الخاص بها.
- تعريف مصفوفة
columnWidth. - تعريف مصفوفة
rowHeight. - إضافة كائن ITable إلى الشريحة عبر طريقة addTable.
- تكرار كل ICell لتطبيق تنسيق على الحدود العليا والسفلى واليمين واليسار.
- دمج الخليتين الأوليين في الصف الأول من الجدول.
- الوصول إلى TextFrame الخاص بـ ICell.
- إضافة بعض النص إلى TextFrame.
- حفظ العرض المعدل.
This Java code shows you how to create a table in a presentation:
// إنشاء كائن من فئة Presentation التي تمثل ملف PPTX
Presentation pres = new Presentation();
try {
// الوصول إلى الشريحة الأولى
ISlide sld = pres.getSlides().get_Item(0);
// تعريف الأعمدة بعرضها والصفوف بارتفاعها
double[] dblCols = {50, 50, 50};
double[] dblRows = {50, 30, 30, 30, 30};
// إضافة شكل جدول إلى الشريحة
ITable tbl = sld.getShapes().addTable(100, 50, dblCols, dblRows);
// تعيين تنسيق الحدود لكل خلية
for (int row = 0; row < tbl.getRows().size(); row++)
{
for (int cell = 0; cell < tbl.getRows().get_Item(row).size(); cell++)
{
ICellFormat cellFormat = tbl.getRows().get_Item(row).get_Item(cell).getCellFormat();
cellFormat.getBorderTop().getFillFormat().setFillType(FillType.Solid);
cellFormat.getBorderTop().getFillFormat().getSolidFillColor().setColor(Color.RED);
cellFormat.getBorderTop().setWidth(5);
cellFormat.getBorderBottom().getFillFormat().setFillType(FillType.Solid);
cellFormat.getBorderBottom().getFillFormat().getSolidFillColor().setColor(Color.RED);
cellFormat.getBorderBottom().setWidth(5);
cellFormat.getBorderLeft().getFillFormat().setFillType(FillType.Solid);
cellFormat.getBorderLeft().getFillFormat().getSolidFillColor().setColor(Color.RED);
cellFormat.getBorderLeft().setWidth(5);
cellFormat.getBorderRight().getFillFormat().setFillType(FillType.Solid);
cellFormat.getBorderRight().getFillFormat().getSolidFillColor().setColor(Color.RED);
cellFormat.getBorderRight().setWidth(5);
}
}
// دمج الخلايا 1 و 2 في الصف 1
tbl.mergeCells(tbl.getRows().get_Item(0).get_Item(0), tbl.getRows().get_Item(1).get_Item(1), false);
// إضافة بعض النص إلى الخلية المدمجة
tbl.getRows().get_Item(0).get_Item(0).getTextFrame().setText("Merged Cells");
// حفظ العرض التقديمي إلى القرص
pres.save("table.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
الترقيم في جدول قياسي
في جدول قياسي، يكون ترقيم الخلايا بسيطًا ويبدأ من الصفر. يتم فهرسة الخلية الأولى في الجدول كـ 0,0 (العمود 0، الصف 0).
على سبيل المثال، يتم ترقيم الخلايا في جدول يحتوي على 4 أعمدة و4 صفوف بهذه الطريقة:
| (0, 0) | (1, 0) | (2, 0) | (3, 0) |
|---|---|---|---|
| (0, 1) | (1, 1) | (2, 1) | (3, 1) |
| (0, 2) | (1, 2) | (2, 2) | (3, 2) |
| (0, 3) | (1, 3) | (2, 3) | (3, 3) |
This Java code shows you how to specify the numbering for cells in a table:
// ينشئ كائنًا من فئة Presentation تمثل ملف PPTX
Presentation pres = new Presentation();
try {
// يصل إلى الشريحة الأولى
ISlide sld = pres.getSlides().get_Item(0);
// يحدد الأعمدة بعرضها والصفوف بارتفاعها
double[] dblCols = { 70, 70, 70, 70 };
double[] dblRows = { 70, 70, 70, 70 };
// يضيف شكل جدول إلى الشريحة
ITable tbl = sld.getShapes().addTable(100, 50, dblCols, dblRows);
// يضبط تنسيق الحدود لكل خلية
for (IRow row : tbl.getRows())
{
for (ICell cell : row)
{
cell.getCellFormat().getBorderTop().getFillFormat().setFillType(FillType.Solid);
cell.getCellFormat().getBorderTop().getFillFormat().getSolidFillColor().setColor(Color.RED);
cell.getCellFormat().getBorderTop().setWidth(5);
cell.getCellFormat().getBorderBottom().getFillFormat().setFillType(FillType.Solid);
cell.getCellFormat().getBorderBottom().getFillFormat().getSolidFillColor().setColor(Color.RED);
cell.getCellFormat().getBorderBottom().setWidth(5);
cell.getCellFormat().getBorderLeft().getFillFormat().setFillType(FillType.Solid);
cell.getCellFormat().getBorderLeft().getFillFormat().getSolidFillColor().setColor(Color.RED);
cell.getCellFormat().getBorderLeft().setWidth(5);
cell.getCellFormat().getBorderRight().getFillFormat().setFillType(FillType.Solid);
cell.getCellFormat().getBorderRight().getFillFormat().getSolidFillColor().setColor(Color.RED);
cell.getCellFormat().getBorderRight().setWidth(5);
}
}
// حفظ العرض التقديمي إلى القرص
pres.save("StandardTables_out.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
الوصول إلى جدول موجود
-
إنشاء مثيل من الفئة Presentation.
-
الحصول على مرجع الشريحة التي تحتوي على الجدول عبر الفهرس الخاص بها.
-
إنشاء كائن ITable وتعيينه إلى null.
-
تكرار جميع كائنات IShape حتى يتم العثور على الجدول.
إذا كنت تشك أن الشريحة التي تتعامل معها تحتوي على جدول واحد، يمكنك ببساطة التحقق من جميع الأشكال التي تحتويها. عندما يتم التعرف على شكل على أنه جدول، يمكنك تحويل نوعه إلى كائن Table. لكن إذا كانت الشريحة التي تتعامل معها تحتوي على عدة جداول، فمن الأفضل البحث عن الجدول المطلوب عبر خاصية setAlternativeText(String value).
-
استخدم كائن ITable للعمل مع الجدول. في المثال أدناه، أضفنا صفًا جديدًا إلى الجدول.
-
حفظ العرض المعدل.
This Java code shows you how to access and work with an existing table:
// ينشئ كائنًا من فئة Presentation التي تمثل ملف PPTX
Presentation pres = new Presentation("UpdateExistingTable.pptx");
try {
// الوصول إلى الشريحة الأولى
ISlide sld = pres.getSlides().get_Item(0);
// تهيئة TableEx بقيمة null
ITable tbl = null;
// يتنقل عبر الأشكال ويعيّن مرجعًا للجدول الموجود
for (IShape shp : sld.getShapes())
{
if (shp instanceof ITable)
{
tbl = (ITable) shp;
// يضبط النص للعمود الأول من الصف الثاني
tbl.get_Item(0, 1).getTextFrame().setText("New");
}
}
// حفظ العرض التقديمي المعدل إلى القرص
pres.save("table1_out.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
محاذاة النص في جدول
- إنشاء مثيل من الفئة Presentation.
- الحصول على مرجع الشريحة عبر الفهرس الخاص بها.
- إضافة كائن ITable إلى الشريحة.
- الوصول إلى كائن ITextFrame من الجدول.
- الوصول إلى IParagraph الخاص بـ ITextFrame.
- محاذاة النص عمودياً.
- حفظ العرض المعدل.
This Java code shows you how to align the text in a table:
// ينشئ مثيلًا من فئة Presentation
Presentation pres = new Presentation();
try {
// يحصل على الشريحة الأولى
ISlide slide = pres.getSlides().get_Item(0);
// يحدد الأعمدة بعرضها والصفوف بارتفاعها
double[] dblCols = { 120, 120, 120, 120 };
double[] dblRows = { 100, 100, 100, 100 };
// يضيف شكل جدول إلى الشريحة
ITable tbl = slide.getShapes().addTable(100, 50, dblCols, dblRows);
tbl.get_Item(1, 0).getTextFrame().setText("10");
tbl.get_Item(2, 0).getTextFrame().setText("20");
tbl.get_Item(3, 0).getTextFrame().setText("30");
// يحصل على إطار النص
ITextFrame txtFrame = tbl.get_Item(0, 0).getTextFrame();
// ينشئ كائن Paragraph لإطار النص
IParagraph paragraph = txtFrame.getParagraphs().get_Item(0);
// ينشئ كائن Portion للفقرة
IPortion portion = paragraph.getPortions().get_Item(0);
portion.setText("Text here");
portion.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
portion.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
// يضبط محاذاة النص عموديًا
ICell cell = tbl.get_Item(0, 0);
cell.setTextAnchorType(TextAnchorType.Center);
cell.setTextVerticalType(TextVerticalType.Vertical270);
// يحفظ العرض التقديمي إلى القرص
pres.save("Vertical_Align_Text_out.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
تعيين تنسيق النص على مستوى الجدول
- إنشاء مثيل من الفئة Presentation.
- الحصول على مرجع الشريحة عبر الفهرس الخاص بها.
- الوصول إلى كائن ITable من الشريحة.
- تعيين setFontHeight(float value) للنص.
- تعيين setAlignment(int value) و setMarginRight(float value).
- تعيين setTextVerticalType(byte value).
- حفظ العرض المعدل.
This Java code shows you how to apply your preferred formatting options to the text in a table:
// إنشاء مثيل من فئة Presentation
Presentation pres = new Presentation("simpletable.pptx");
try {
// نفترض أن الشكل الأول في الشريحة الأولى هو جدول
ITable someTable = (ITable) pres.getSlides().get_Item(0).getShapes().get_Item(0);
// يضبط ارتفاع خط خلايا الجدول
PortionFormat portionFormat = new PortionFormat();
portionFormat.setFontHeight(25);
someTable.setTextFormat(portionFormat);
// يضبط محاذاة نص خلايا الجدول والهوامش اليمنى في استدعاء واحد
ParagraphFormat paragraphFormat = new ParagraphFormat();
paragraphFormat.setAlignment(TextAlignment.Right);
paragraphFormat.setMarginRight(20);
someTable.setTextFormat(paragraphFormat);
// يضبط نوع النص العمودي لخلايا الجدول
TextFrameFormat textFrameFormat = new TextFrameFormat();
textFrameFormat.setTextVerticalType(TextVerticalType.Vertical);
someTable.setTextFormat(textFrameFormat);
pres.save("result.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
الحصول على خصائص نمط الجدول
تسمح لك Aspose.Slides باسترجاع خصائص النمط لجدول حتى تتمكن من استخدام هذه التفاصيل لجدول آخر أو في مكان آخر. يُظهر هذا الكود Java كيفية الحصول على خصائص النمط من نمط جدول مسبق:
Presentation pres = new Presentation();
try {
ITable table = pres.getSlides().get_Item(0).getShapes().addTable(10, 10, new double[] { 100, 150 }, new double[] { 5, 5, 5 });
table.setStylePreset(TableStylePreset.DarkStyle1); // تغيير سمة النمط المسبق الافتراضي
pres.save("table.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
قفل نسبة العرض إلى الارتفاع للجدول
نسبة العرض إلى الارتفاع لشكل هندسي هي نسبة أبعاده المختلفة. قدمت Aspose.Slides الخاصية setAspectRatioLocked للسماح لك بقفل إعداد نسبة العرض إلى الارتفاع للجداول والأشكال الأخرى.
This Java code shows you how to lock the aspect ratio for a table:
Presentation pres = new Presentation("pres.pptx");
try {
ITable table = (ITable)pres.getSlides().get_Item(0).getShapes().get_Item(0);
System.out.println("Lock aspect ratio set: " + table.getGraphicalObjectLock().getAspectRatioLocked());
table.getGraphicalObjectLock().setAspectRatioLocked(!table.getGraphicalObjectLock().getAspectRatioLocked()); // عكس
System.out.println("Lock aspect ratio set: " + table.getGraphicalObjectLock().getAspectRatioLocked());
pres.save("pres-out.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
الأسئلة الشائعة
هل يمكنني تمكين اتجاه القراءة من اليمين إلى اليسار (RTL) لجدول كامل والنص داخل خلاياه؟
نعم. يعرض الجدول طريقة setRightToLeft، وتحتوي الفقرات على ParagraphFormat.setRightToLeft. يضمن استخدام الطريقتين الترتيب الصحيح للـ RTL وعرضه داخل الخلايا.
كيف يمكنني منع المستخدمين من نقل أو تغيير حجم الجدول في الملف النهائي؟
استخدم أقفال الشكل لتعطيل النقل، تغيير الحجم، التحديد، وما إلى ذلك. تنطبق هذه الأقفال على الجداول أيضًا.
هل يدعم إدراج صورة داخل خلية كخلفية؟
نعم. يمكنك تعيين picture fill للخلية؛ ستغطي الصورة مساحة الخلية وفقًا للوضع المختار (تمدد أو تجانب).