LoginSignup
0
1

More than 5 years have passed since last update.

C#はテキストと画像を含むPowerPointドクムを生成

Posted at

PowerPointドキュメント(スライド)は、一般的なプレゼンテーションのドキュメントであり、スピーチ、教育、製品のプレゼンテーションなどの面で広く応用されている。この文は、簡単なPowerPointファイルを作成する方法を紹介します。

以下のコードを使用する前に必要:

  1. ダウンロードFree Spire.Presentation,インストール経路から引用Spire.Presentation.dllアプリケーション.
  2. 名のスペースを引用する:
using Spire.Presentation;
using Spire.Presentation.Drawing;

簡単なPowerPointドキュメントを作成

// 新しいPowerPointドキュメントを作成します(デフォルトの1ページの空白のスライドを含む) Presentation ppt = new Presentation();

 //スライドサイズと方向を設定
 ppt.SlideSize.Type = SlideSizeType.Screen16x9;
 ppt.SlideSize.Orientation = SlideOrienation.Landscape;

 //スライドに背景画像を設定する
 string ImageFile = "background.png";
 RectangleF rect = new RectangleF(0, 0, ppt.SlideSize.Size.Width, ppt.SlideSize.Size.Height);
 ppt.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Picture;
 IEmbedImage image = ppt.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect);
 ppt.Slides[0].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image as IImageData;

 //第1枚のスライドにパターンを追加
 IAutoShape textboxShape = ppt.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 70, 600, 100));
 textboxShape.ShapeStyle.LineColor.Color = Color.Transparent;
 textboxShape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None;

 //図形の段落をクリアする(デフォルトの空白がある)
 textboxShape.TextFrame.Paragraphs.Clear();

 //図形に段落と内容を追加する
 textboxShape.TextFrame.Paragraphs.Append(new TextParagraph());
 textboxShape.TextFrame.Paragraphs[0].TextRanges.Append(new TextRange("Spire.Presentation for .NET"));
 textboxShape.TextFrame.Paragraphs[0].SpaceAfter = 50f;

 //第2段の内容を追加
 textboxShape.TextFrame.Paragraphs.Append(new TextParagraph());
 string text = "プロフェッショナルのPowerPointコンポーネントは、PowerPointドキュメントの生成、読み取り、書き込み、修正、変換、印刷などの操作を行うことができます。";
 textboxShape.TextFrame.Paragraphs[1].TextRanges.Append(new TextRange(text));

 //段落中の文字のフォント、サイズ、色、段落の揃え方、段首が距離を縮める
 foreach (TextParagraph para in textboxShape.TextFrame.Paragraphs)
 {
     para.TextRanges[0].LatinFont = new TextFont("Arial Rounded MT Bold");
     para.TextRanges[0].FontHeight = 13f;
     para.TextRanges[0].Fill.FillType = FillFormatType.Solid;
     para.TextRanges[0].Fill.SolidColor.Color = Color.Black;
     para.Alignment = TextAlignmentType.Left;
     para.Indent = 35;
 }

 //ファイルを保存する
 ppt.SaveToFile("CreatPPT.pptx", FileFormat.Pptx2013);  

効果図:
Create PowerPoint.png

総括する
ネットでPowerPointの部品を操作するのは多くありません,Free Spire.Presentation優勢は無料で使いやすい,機能がそろっている,ただ、無料版だけで10枚のスライドを処理する制限があります,普通の利用者にとっては十分だ,より大きなスライドドキュメントを操作する必要がある場合,ビジネス版もあります,ページ制限はない。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1