كيفية إدراج صورة في PowerPoint Table باستخدام Python

يركز هذا المثال على كيفية ** إدراج صورة في PowerPoint Table باستخدام Python **. يصف جميع المعلومات المطلوبة لإعداد البيئة وكود مثال عملي ** لإضافة صورة في جدول PPTX في Python **. يمكن استخدام التطبيق في أي بيئة مكونة من Python مثل Linux أو macOS أو Windows.

خطوات إدراج الصورة في PowerPoint Table باستخدام Python

  1. قم بتهيئة البيئة لـ استخدم Aspose.Slides لـ Python عبر .NET لإدراج صورة داخل الجدول
  2. قم بإنشاء عرض تقديمي افتراضي باستخدام مثيل من فئة Presentation ثم قم بالوصول إلى الشريحة الأولى من مجموعة الشرائح
  3. أدخل جدولاً بالداخل يحتوي على عدد محدد مسبقًا من الصفوف والأعمدة داخل الشريحة المحددة باستخدام طريقة add_table()
  4. أدخل الصورة داخل مجموعة صور العرض التقديمي
  5. قم بالوصول إلى الخلية التي تنتمي إلى الصف الأول والعمود داخل الجدول وقم بتعيين الصورة بداخلها
  6. احفظ العرض التقديمي PPTX مع صورة جدول على القرص

لقد اكتشفنا كيفية * عرض الصورة في جدول PPTX في Python * باستخدام الخطوات المذكورة أعلاه. في البداية ، سيتم إنشاء عرض تقديمي افتراضي باستخدام مثيل لفئة العرض التقديمي مع الوصول إلى الشريحة الأولى داخل مجموعة شرائح العرض التقديمي. سننشئ جدولًا جديدًا باستخدام الأرقام المحددة مسبقًا للصفوف والأعمدة باستخدام طريقة add_table () ، والتي يتبعها بعد ذلك تحميل الصورة المصدر من القرص وإدخالها داخل مجموعة صور العرض التقديمي. في النهاية ، سنقوم بتعيين الصورة المضافة داخل خلية الجدول قبل حفظ العرض التقديمي على القرص.

كود لإدراج صورة في PowerPoint Table باستخدام Python

import aspose.pydrawing as draw
import aspose.slides as slides
#Path to the license and image file directory
filepath = "Y://Documents//KnowledgeBase//TestData//"
# Load the license in your application for creating a table with an image
slidesTableLicense = slides.License()
slidesTableLicense.set_license(filepath + "Conholdate.Total.Product.Family.lic")
#Create a Presentation object to add a table with an image
with slides.Presentation() as presTable:
# Access the first slide to add the table
slideForTable = presTable.slides[0]
#Define the rows' heights and columns' widths
dblColWidth = [50, 50, 50]
dblRowHeight = [50, 30, 32, 30]
#Add a table shape to slide
tblwithImage = slideForTable.shapes.add_table(100, 50, dblColWidth, dblRowHeight)
with open(filepath + "sample.png", "rb") as bin_file:
#Read the entire file from the disk at once
tblImageData = bin_file.read()
#Insert the image insdie the images collection of the presentation
imageForSlide = presTable.images.add_image(tblImageData)
#Access the first cells inside the first row of the table
tableCell = tblwithImage[0,0]
#Set the cell fill format to picture
tableCell.cell_format.fill_format.fill_type = slides.FillType.PICTURE
#Set the picture fill mode
tableCell.cell_format.fill_format.picture_fill_format.picture_fill_mode = slides.PictureFillMode.STRETCH
#Set the image for the selected cell inside the table
tableCell.cell_format.fill_format.picture_fill_format.picture.image = imageForSlide
#Save the presentations with table image
presTable.save(filepath + "PresWithTableImage.pptx", slides.export.SaveFormat.PPTX)
print("Done")

يعرض المثال أعلاه ، كيفية * إدراج صورة جدول في شريحة باستخدام Python * باستخدام واجهة API بسيطة للغاية. يتم استخدام تنسيق cell_format لتعيين تنسيق التعبئة للخلية على صورة باستخدام عداد Fill_type.PICTURE. لقد أضفنا صورة PNG لخلية الجدول في هذا المثال. ومع ذلك ، يمكنك أيضًا إضافة أنواع صور أخرى بما في ذلك JPEG و BMP و EMF و SVG لخلايا الجدول أيضًا.

في هذا الموضوع ، قمنا بتوجيهك من خلال * كيف ستدرج صورة جدول في عرض تقديمي باستخدام Python *. إذا كنت تريد معرفة المزيد حول إدارة الجداول داخل PowerPoint ، فارجع إلى الموضوع ، كيفية إنشاء جدول في PowerPoint باستخدام Python.

 عربي