この簡単なチュートリアルでは、** C#を使用してPowerPoint Presentationを作成する方法**と、環境をセットアップするための詳細な手順を示します。 * C#で作業しているときに、PowerPointに依存せずに簡単な手順でPowerPoint*プレゼンテーションを作成します。さらに、提供されている例は、.NETでサポートされているすべてのプラットフォームでシームレスに使用できます。
C#を使用してPowerPointプレゼンテーションを作成する手順
- NuGetからAspose.Slides for .NETパッケージをダウンロードしてインストールします
- プロジェクトでAspose.Slides、Aspose.Slides.Export、およびSystem.Drawing名前空間を使用します
- Presentationクラスのインスタンスを使用して、空のプレゼンテーションを作成します
- プレゼンテーションスライドコレクション内に空白レイアウトタイプのスライドを追加します
- 新しく作成したスライド内に長方形のオートシェイプを追加します
- 追加された図形の内側にテキストフレームを追加し、そのテキストプロパティを設定します
- Saveメソッドを使用して、プレゼンテーションをPPTXとしてディスクに保存します
- C#の上記の手順では、MSPowerPointに依存せずにPPTXファイル*を作成します。このプロセスは、Presentationクラスインスタンスを使用してプレゼンテーションを作成することから始まり、その後、空白のスライドとスライド内にオートシェイプを追加します。続いて、プレゼンテーションファイルをPPTXとしてディスクに保存する前に、テキストが追加され、追加された図形内にフォーマットされます。
C#でPowerPointプレゼンテーションを生成するコード
using System; | |
using System.Drawing; | |
using Aspose.Slides; | |
using Aspose.Slides.Export; | |
namespace TestSlides | |
{ | |
public class CreatePresentation | |
{ | |
public static void GeneratePresentation() | |
{ | |
// Setting the linence for the product | |
License SlidesLicense = new License(); | |
SlidesLicense.SetLicense("Aspose.Total.lic"); | |
// Create an empty presentation using Presentation class object | |
using (Presentation presentation = new Presentation()) | |
{ | |
// Add a Blank slide inside the presentation | |
ISlide slide = presentation.Slides.AddEmptySlide(presentation.LayoutSlides.GetByType(SlideLayoutType.Blank)); | |
// Insert a Rectangle autoshape inside the slide | |
IAutoShape autoShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 150, 300, 0); | |
// Filling the shape with color | |
autoShape.FillFormat.FillType = FillType.Solid; | |
autoShape.FillFormat.SolidFillColor.Color = Color.Green; | |
// Include some text inside the shape | |
ITextFrame txtFrame = autoShape.AddTextFrame("Welcome to Aspose Knowledgebase examples"); | |
// Set textual properties | |
IPortionFormat portionFormat = txtFrame.Paragraphs[0].Portions[0].PortionFormat; | |
portionFormat.FillFormat.FillType = FillType.Solid; | |
portionFormat.FillFormat.SolidFillColor.Color = Color.Red; | |
portionFormat.FontBold = NullableBool.True; | |
portionFormat.FontItalic = NullableBool.True; | |
portionFormat.FontHeight = 14; | |
// Save the presentation on the disk | |
presentation.Save("NewPresentation.pptx", SaveFormat.Pptx); | |
} | |
} | |
} | |
} |
上記の例をC#プレゼンテーションで使用することにより、PPTX形式でディスクに保存されています。 SaveFormat列挙子には、プレゼンテーションをPPT、PPS、PPSX、ODP、POT、およびPOTX形式で保存するためのオプションもあります。また、PortionFormatおよびParagraphFormatクラスによって公開されるさまざまなオプションを使用してテキストをカスタマイズすることもできます。これには、箇条書き、余白、インデント、強調表示、テキストの取り消し線などのオプションの設定が含まれます。
以前、別のハウツートピックでスライドをC#でSVGとして保存する方法を目撃しました。ただし、このトピックでは、さまざまな形式で* C#PowerPointプレゼンテーション*を使用して生成する方法について説明しました。