0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PPT文書の画像を置き換える

Last updated at Posted at 2018-09-26

この資料では、Spire.Presentationを使用してPPTドキュメントのイメージを置き換える方法について説明します。
ツール:Spire.Presentation for .NET; Visual Studio
元の文書は次のとおりです:
1.jpg
方法、ステップ
ステップ1: Spire.Presentation for .NETをダウンロードしてインストールし、プロジェクトにSpire.Presentation.dllファイルを参照します。
ステップ2: Visual Studioにコードを挿入する:

C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;

namespace Replace_Image3
{
    class Program
    {
        static void Main(string[] args)
        {
            //プレゼンテーションインスタンスを作成する
            Presentation ppt = new Presentation();
            //PowerPointドキュメントを読み込む
            ppt.LoadFromFile("テスト.pptx");

            //最初のスライドを取得する
            ISlide slide = ppt.Slides[0];

            //指定したイメージを置き換える新しいイメージを追加する
            IImageData image = ppt.Images.Append(Image.FromFile("ピクチャ.jpg"));

            //スライド内の図形を横断する
            foreach (IShape shape in slide.Shapes)
            {
                //図形が写真かどうかを判断する
                if (shape is SlidePicture)
                {
                    //画像のタイトルを決定する
                    if (shape.AlternativeTitle == "イメージ1")
                    {
                        //イメージ1というタイトルの画像を新しい画像に置き換えます
                        (shape as SlidePicture).PictureFill.Picture.EmbedImage = image;
                    }
                }
            }

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

        }
    }
}

コードをデバッグして実行した後、生成されたドキュメントは図のようになります:
2.jpg

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?