.NET で PowerPoint プレゼンテーションを Word 文書に変換
概要
本記事は、開発者向けに Aspose.Slides for .NET と Aspose.Words for .NET を使用して PowerPoint および OpenDocument のプレゼンテーションを Word 文書に変換するソリューションを提供します。ステップバイステップのガイドで変換プロセスのすべての段階を案内します。
プレゼンテーションを Word 文書に変換する
以下の手順に従って、PowerPoint または OpenDocument のプレゼンテーションを Word 文書に変換します。
- Presentation クラスのインスタンスを作成し、プレゼンテーション ファイルをロードします。
- Document と DocumentBuilder クラスのインスタンスを作成して、Word 文書を生成します。
- DocumentBuilder.PageSetup プロパティを使用して、Word 文書のページサイズをプレゼンテーションと同じに設定します。
- DocumentBuilder.PageSetup プロパティを使用して、Word 文書の余白を設定します。
- Presentation.Slides プロパティを使用して、すべてのプレゼンテーション スライドを処理します。
- ISlide インターフェイスの
GetImageメソッドを使用してスライド画像を生成し、メモリ ストリームに保存します。 - DocumentBuilder クラスの
InsertImageメソッドを使用して、スライド画像を Word 文書に追加します。
- ISlide インターフェイスの
- Word 文書をファイルに保存します。
例として、以下のようなプレゼンテーション “sample.pptx” があるとします:

以下の C# コード例は、PowerPoint プレゼンテーションを Word 文書に変換する方法を示しています:
// プレゼンテーション ファイルをロードします。
using var presentation = new Presentation("sample.pptx");
// Document と DocumentBuilder オブジェクトを作成します。
var document = new Document();
var builder = new DocumentBuilder(document);
// Word 文書のページサイズを設定します。
var slideSize = presentation.SlideSize.Size;
builder.PageSetup.PageWidth = slideSize.Width;
builder.PageSetup.PageHeight = slideSize.Height;
// Word 文書の余白を設定します。
builder.PageSetup.LeftMargin = 0;
builder.PageSetup.RightMargin = 0;
builder.PageSetup.TopMargin = 0;
builder.PageSetup.BottomMargin = 0;
const float scaleX = 2, scaleY = 2;
// すべてのプレゼンテーション スライドを処理します。
foreach (var slide in presentation.Slides)
{
// スライド画像を生成し、メモリ ストリームに保存します。
using var image = slide.GetImage(scaleX, scaleY);
using var imageStream = new MemoryStream();
image.Save(imageStream, ImageFormat.Png);
// スライド画像を Word 文書に追加します。
imageStream.Seek(0, SeekOrigin.Begin);
builder.InsertImage(imageStream.ToArray(), builder.PageSetup.PageWidth, builder.PageSetup.PageHeight);
builder.InsertBreak(BreakType.PageBreak);
}
// Word 文書をファイルに保存します。
document.Save("output.docx");
結果:

FAQ
PowerPoint と OpenDocument のプレゼンテーションを Word 文書に変換するために必要なコンポーネントは何ですか?
C# プロジェクトに Aspose.Slides for .NET と Aspose.Words for .NET の対応する NuGet パッケージを追加するだけで済みます。両方のライブラリはスタンドアロンの API として動作し、Microsoft Office のインストールは必要ありません。
すべての PowerPoint および OpenDocument プレゼンテーション形式がサポートされていますか?
Aspose.Slides for .NET は すべてのプレゼンテーション形式をサポート しており、PPT、PPTX、ODP などの一般的なファイル形式が含まれます。これにより、さまざまなバージョンの Microsoft PowerPoint で作成されたプレゼンテーションを扱うことができます。