この簡単なチュートリアルでは、C# を使用して Excel を PowerPoint に埋め込む プロセスについて説明します。開発環境を設定するための詳細、アプリケーションを作成する手順の一覧、C# を使用して Excel ファイルを PowerPoint に埋め込む方法 を示すサンプル コードを提供します。スライドの指定されたフレーム内に Excel ファイルを埋め込む方法を学習します。
C# を使用して Excel ファイルを PowerPoint に埋め込む手順
- IDE を設定して Aspose.Slides for .NET を使用して Excel ファイルをプレゼンテーションに埋め込む
- Presentationクラスオブジェクトを作成する
- Excelファイルを埋め込む最初のスライドにアクセスします
- ExcelファイルをMemoryStreamオブジェクトに読み込む
- embedded data information オブジェクトを作成する
- 必要なパラメータを使用して、スライドにOLEオブジェクトフレームを追加します。
- プレゼンテーションを保存する
C# を使用して Excel ファイルを PowerPoint に埋め込む方法を学習するには、次の手順に従ってください。Presentation クラスのオブジェクトを作成し、対象のスライドにアクセスして、ソース Excel ファイルを MemoryStream に読み込みます。スライド上の指定された位置に幅と高さを指定して OleEmbeddedDataInfo オブジェクトを作成し、最後に OLE オブジェクトをプレゼンテーションに追加します。
C# を使用して Excel ブックを PowerPoint に挿入するコード
using System; | |
using System.IO; | |
using Aspose.Slides; | |
using Aspose.Slides.Export; | |
using Aspose.Slides.DOM.Ole; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
new License().SetLicense("License.lic"); | |
// Instantiates the Presentation object | |
using (Presentation presentation = new Presentation()) | |
{ | |
// Get the first slide | |
ISlide sld = presentation.Slides[0]; | |
// Read the XLSX file into the MemoryStream | |
byte[] fileBytes = File.ReadAllBytes("book1.xlsx"); | |
MemoryStream memoryStream = new MemoryStream(fileBytes); | |
// Create a data object | |
IOleEmbeddedDataInfo EmbeddedDataInfo = new OleEmbeddedDataInfo(memoryStream.ToArray(), "xlsx"); | |
// Add an Ole Object Frame shape | |
IOleObjectFrame oleObjectFrame = sld.Shapes.AddOleObjectFrame(0, 0, presentation.SlideSize.Size.Width, | |
presentation.SlideSize.Size.Height, EmbeddedDataInfo); | |
// Write the PPTX file | |
presentation.Save("Output.pptx", SaveFormat.Pptx); | |
} | |
Console.WriteLine("Excel File embedded successfully"); | |
} | |
} |
このコードは、C# を使用して Excel を PowerPoint に埋め込む方法 を示しています。複数のスライドに対してこのプロセスを繰り返し、要件に基づいてさまざまなファイル タイプを追加します。別のオーバーロードされた AddOleObjectFrame() メソッドは、OLE クラス名とリンクされたファイルへのパスを受け入れます。
この記事では、C# を使用して Excel ファイルを PowerPoint に埋め込む 方法について説明しました。プレゼンテーションにオーディオを追加するには、次の記事を参照してください: C# を使用してプレゼンテーションにオーディオを追加する方法。