VSTO および Java を介した Aspose.Slides for PHP を使用してテキストをフォーマットする
Contents
[
Hide
]
場合によっては、スライド上のテキストをプログラムでフォーマットする必要があります。この記事では、VSTO および Aspose.Slides for PHP via Java を使用して、最初のスライドにあるいくつかのテキストを含むサンプルプレゼンテーションを読み取る方法を示します。コードは、スライドの3番目のテキストボックスのテキストを最後のテキストボックスのテキストのように見えるようにフォーマットします。
テキストのフォーマット
VSTO と Aspose.Slides の両方の方法は、次の手順を踏みます:
- ソースプレゼンテーションを開く。
- 最初のスライドにアクセスする。
- 3番目のテキストボックスにアクセスする。
- 3番目のテキストボックスのテキストのフォーマットを変更する。
- プレゼンテーションをディスクに保存する。
以下のスクリーンショットは、VSTO と PHP を介した Aspose.Slides の実行前後のサンプルスライドを示しています。
入力プレゼンテーション
VSTO コード例
以下のコードは、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; | |
PowerPoint.Presentation pres = null; | |
//Open the presentation | |
pres = Globals.ThisAddIn.Application.Presentations.Open("c:\\source.ppt", | |
Microsoft.Office.Core.MsoTriState.msoFalse, | |
Microsoft.Office.Core.MsoTriState.msoFalse, | |
Microsoft.Office.Core.MsoTriState.msoTrue); | |
//Access the first slide | |
PowerPoint.Slide slide = pres.Slides[1]; | |
//Access the third shape | |
PowerPoint.Shape shp = slide.Shapes[3]; | |
//Change its text's font to Verdana and height to 32 | |
PowerPoint.TextRange txtRange = shp.TextFrame.TextRange; | |
txtRange.Font.Name = "Verdana"; | |
txtRange.Font.Size = 32; | |
//Bolden it | |
txtRange.Font.Bold = Microsoft.Office.Core.MsoTriState.msoCTrue; | |
//Italicize it | |
txtRange.Font.Italic = Microsoft.Office.Core.MsoTriState.msoCTrue; | |
//Change text color | |
txtRange.Font.Color.RGB = 0x00CC3333; | |
//Change shape background color | |
shp.Fill.ForeColor.RGB = 0x00FFCCCC; | |
//Reposition it horizontally | |
shp.Left -= 70; | |
//Write the output to disk | |
pres.SaveAs("c:\\outVSTO.ppt", | |
PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, | |
Microsoft.Office.Core.MsoTriState.msoFalse); |
Java を介した Aspose.Slides for PHP の例
Aspose.Slides でテキストをフォーマットするには、テキストをフォーマットする前にフォントを追加します。
Aspose.Slides で作成された出力プレゼンテーション
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
//Open the presentation | |
Presentation pres = new Presentation("c:\\source.ppt"); | |
//Access the first slide | |
ISlide slide = pres.getSlides().get_Item(0); | |
//Access the third shape | |
IShape shp = slide.getShapes().get_Item(2); | |
//Change its text's font to Verdana and height to 32 | |
ITextFrame tf = ((IAutoShape)shp).getTextFrame(); | |
IParagraph para = tf.getParagraphs().get_Item(0); | |
IPortion port = para.getPortions().get_Item(0); | |
port.getPortionFormat().setLatinFont(new FontData("Verdana")); | |
port.getPortionFormat().setFontHeight(32); | |
//Bolden it | |
port.getPortionFormat().setFontBold(NullableBool.True); | |
//Italicize it | |
port.getPortionFormat().setFontItalic(NullableBool.True); | |
//Change text color | |
//Set font color | |
port.getPortionFormat().getFillFormat().setFillType(FillType.Solid); | |
port.getPortionFormat().getFillFormat().getSolidFillColor().setColor(new java.awt.Color(0x33, 0x33, 0xCC)); | |
//Change shape background color | |
shp.getFillFormat().setFillType(FillType.Solid); | |
shp.getFillFormat().getSolidFillColor().setColor( new java.awt.Color(0xCC, 0xCC, 0xFF)); | |
//Write the output to disk | |
pres.save("c:\\data\\outAsposeSlides.pptx",SaveFormat.Pptx); |