إضافة نص ديناميكي باستخدام VSTO و Aspose.Slides لنظام Android عبر Java
Contents
[
Hide
]
وظيفة شائعة يجب على المطورين إنجازها هي إضافة نص إلى الشرائح ديناميكيًا. تعرض هذه المقالة أمثلة كود لإضافة نص ديناميكيًا باستخدام VSTO وAspose.Slides لنظام Android عبر Java.
إضافة نص ديناميكي
تتبع كلا الطريقتين الخطوات التالية:
- إنشاء عرض تقديمي.
- إضافة شريحة فارغة.
- إضافة مربع نص.
- تعيين نص.
- كتابة العرض التقديمي.
مثال على كود VSTO
تؤدي مقاطع الكود أدناه إلى إنشاء عرض تقديمي مع شريحة بسيطة وسلسلة من النصوص عليها.
العرض التقديمي كما تم إنشاؤه في VSTO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Note: PowerPoint is a namespace which has been defined above like this | |
//using PowerPoint = Microsoft.Office.Interop.PowerPoint; | |
//Create a presentation | |
PowerPoint.Presentation pres = Globals.ThisAddIn.Application | |
.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoFalse); | |
//Get the blank slide layout | |
PowerPoint.CustomLayout layout = pres.SlideMaster. | |
CustomLayouts[7]; | |
//Add a blank slide | |
PowerPoint.Slide sld = pres.Slides.AddSlide(1, layout); | |
//Add a text | |
PowerPoint.Shape shp = sld.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 150, 100, 400, 100); | |
//Set a text | |
PowerPoint.TextRange txtRange = shp.TextFrame.TextRange; | |
txtRange.Text = "Text added dynamically"; | |
txtRange.Font.Name = "Arial"; | |
txtRange.Font.Bold = Microsoft.Office.Core.MsoTriState.msoTrue; | |
txtRange.Font.Size = 32; | |
//Write the output to disk | |
pres.SaveAs("c:\\outVSTO.ppt", | |
PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, | |
Microsoft.Office.Core.MsoTriState.msoFalse); | |
مثال على Aspose.Slides لنظام Android عبر Java
تستخدم مقاطع الكود أدناه Aspose.Slides لإنشاء عرض تقديمي مع شريحة بسيطة وسلسلة من النصوص عليها.
العرض التقديمي كما تم إنشاؤه باستخدام Aspose.Slides لنظام Android عبر Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create a presentation | |
Presentation pres = new Presentation(); | |
//Blank slide is added by default, when you create | |
//presentation from default constructor | |
//So, we don't need to add any blank slide | |
ISlide sld = pres.getSlides().get_Item(1); | |
//Add a textbox | |
//To add it, we will first add a rectangle | |
IShape shp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 1200, 800, 3200, 370); | |
//Hide its line | |
shp.getLineFormat().setStyle(LineStyle.NotDefined); | |
//Then add a textframe inside it | |
ITextFrame tf = ((IAutoShape)shp).getTextFrame(); | |
//Set a text | |
tf.setText("Text added dynamically"); | |
IPortion port = tf.getParagraphs().get_Item(0).getPortions().get_Item(0); | |
port.getPortionFormat().setFontBold(NullableBool.True); | |
port.getPortionFormat().setFontHeight(32); | |
//Write the output to disk | |
pres.save("c:\\data\\outAsposeSlides.pptx",SaveFormat.Pptx); |