قم بإنشاء أشكال مخصصة في PowerPoint باستخدام C# REST API

اتبع هذه المقالة لإنشاء أشكال مخصصة في PowerPoint باستخدام C# REST API. سوف تتعلم كيفية إنشاء وإضافة أشكال مخصصة لبرنامج PowerPoint تلقائيًا باستخدام خدمة C# RESTful. فهو يشارك جميع التفاصيل لإنشاء شكل وتعيين معلماته وإضافتها إلى شريحة معينة.

الشرط الأساسي

خطوات إضافة شكل PPT باستخدام C# REST API

  1. قم بإنشاء كائن SlidesApi وقم بتحميل العرض التقديمي المصدر لإضافة الأشكال إليه
  2. حدد أن نوع الشريحة المراد تعديلها هو شريحة رئيسية
  3. قم بإنشاء كائن شكل جديد بخصائص محددة
  4. أضف الشكل الجديد إلى الشريحة المحددة باستخدام طريقة CreateSpecialSlideShape().
  5. قم بتنزيل ملف العرض التقديمي المحدث بالشكل الجديد بداخله

تشرح هذه الخطوات كيفية إنشاء أشكال العرض التقديمي باستخدام C# REST API. قم بإنشاء كائن SlidesApi، وقم بتحميل العرض التقديمي إلى وحدة التخزين السحابية، وحدد نوع الشريحة المراد تعديلها، وقم بإنشاء كائن الشكل باستخدام المعلمات المطلوبة. أضف الشكل إلى الشريحة الرئيسية وقم بتنزيل العرض التقديمي المحدث بالشكل الجديد بداخله.

كود لإضافة شكل لـ PPT مع واجهة C# REST

using Aspose.Slides.Cloud.Sdk;
using Aspose.Slides.Cloud.Sdk.Model;
using System.IO;
namespace AsposeTestCodes
{
class Program
{
static void Main(string[] args) // For adding custom shape
{
SlidesApi slidesApi = new SlidesApi("API Key", "Secret");
// Upload the presentation file to Aspose cloud storage
FilesUploadResult uploadResult = slidesApi.UploadFile("SamplePresentation.pptx", new MemoryStream(File.ReadAllBytes("SamplePresentation.pptx")));//Source presentation
// Define the file name of the uploaded presentation
string fileName = "SamplePresentation.pptx";
// Specify that the slide type to modify is a Master Slide
SpecialSlideType slideType = SpecialSlideType.MasterSlide;
// Create a new shape object with specific properties
Shape dto = new Shape
{
X = 100, // X-coordinate for the position of the shape
Y = 100, // Y-coordinate for the position of the shape
Width = 500, // Width of the shape
Height = 200, // Height of the shape
ShapeType = GeometryShape.ShapeTypeEnum.Rectangle, // Define the shape type as a rectangle
Text = "New shape" // Text content to be displayed within the shape
};
// Add the new shape to the specified slide (master slide at index 1) and retrieve the created shape
Shape shape = (Shape)slidesApi.CreateSpecialSlideShape(fileName, 1, slideType, dto);
Stream stream = slidesApi.DownloadFile(fileName);
// Save the downloaded presentation file locally with a new name ("PresWithShape.pptx")
var fs = new FileStream("PresWithShape.pptx", FileMode.Create, FileAccess.Write); // Create a file stream for saving
stream.CopyTo(fs); // Copy the content of the downloaded file into the file stream
}
}
}

يوضح هذا الرمز كيفية التعامل مع أشكال الشرائح باستخدام C# RESTful Service. يمكنك إضافة أي نوع من الأشكال باستخدام العداد GeometryShape.ShapeTypeEnum بما في ذلك الخطوط والمثلث والمستطيل والماس وما إلى ذلك. ويتوفر الخيار أيضًا لتحديد أنواع خاصة أخرى من الشرائح مثل LayoutSlide وNotesSlide.

لقد علمتنا هذه المقالة كيفية رسم الأشكال على الشريحة. لإضافة الصور راجع المقالة إضافة صورة إلى PowerPoint باستخدام C# REST API.

 عربي