この記事では、C# REST API を使用して SmartArt を PowerPoint に追加する方法について説明します。 .NET ベースの Cloud SDK を使用して C# ローコード API を使用した PowerPoint SmartArt を自動的に挿入する方法を学習します。 PowerPoint プレゼンテーション スライドでさまざまな種類の SmartArt を作成するためのさまざまなクラスと列挙子について説明します。
前提条件
ダウンロード Aspose.Slides Cloud SDK for Dotnet for inserting SmartArt in slides
上記の SDK を使用して C# プロジェクトをセットアップし、SmartArt グラフィックスを作成します
C# REST API を使用して PowerPoint プレゼンテーション SmartArt を追加する手順
- SmartArt を操作するための資格情報を SlidesApi オブジェクトに設定します。
- スマート グラフィックスを挿入するために、ソース プレゼンテーションをクラウド ストレージにアップロードします。
- SmartArt オブジェクトに必要なプロパティを設定してグラフィックス データを作成します。
- CreateShape() メソッドを使用して SmartArt を挿入します
- SmartArt を追加した後、更新されたプレゼンテーション ファイルをダウンロードします。
これらの手順では、SmartArt for PowerPoint を C# REST API で操作する方法について説明します。 SlidesApi クラス オブジェクトを作成し、ソース プレゼンテーションをアップロードし、位置、サイズ、レイアウト、クイック スタイル、カラー スタイルなどの指定された設定を使用して SmartArt オブジェクトを作成します。最後に、CreateShape() メソッドを使用して、SmartArt の複数のノードがそれぞれのスライドに追加されます。
C# .NET ベースの API を使用して PowerPoint スマート シェイプを追加するコード
using Aspose.Slides.Cloud.Sdk; | |
using Aspose.Slides.Cloud.Sdk.Model; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
namespace AsposeSlidesExample | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// Initialize the Slides API with your credentials | |
var apiClient = new SlidesApi("your_api_key", "your_app_sid"); | |
// Define the presentation file name | |
string presentationName = "SamplePresentation.pptx"; | |
string localFilePath = "SamplePresentation.pptx"; | |
// Upload the presentation to Aspose Cloud storage | |
var uploadResponse = apiClient.UploadFile(presentationName, new MemoryStream(File.ReadAllBytes(localFilePath))); | |
Console.WriteLine("File uploaded successfully."); | |
// Configure SmartArt properties | |
var smartArt = new SmartArt | |
{ | |
X = 50, // Horizontal position of the SmartArt | |
Y = 50, // Vertical position of the SmartArt | |
Width = 250, // Width of the SmartArt | |
Height = 250, // Height of the SmartArt | |
Layout = SmartArt.LayoutEnum.BendingPictureSemiTransparentText, // SmartArt layout | |
QuickStyle = SmartArt.QuickStyleEnum.SimpleFill, // Quick style | |
ColorStyle = SmartArt.ColorStyleEnum.ColoredFillAccent1, // Color style | |
Nodes = new List<SmartArtNode> | |
{ | |
new SmartArtNode { Text = "Planning" }, | |
new SmartArtNode { Text = "Design" }, | |
new SmartArtNode { Text = "Implementation" } | |
} | |
}; | |
// Add SmartArt to the first slide | |
var addedSmartArt = apiClient.CreateShape(presentationName, 1, smartArt); | |
Console.WriteLine("SmartArt added to the presentation successfully."); | |
// Download the updated presentation | |
var updatedPresentationStream = apiClient.DownloadFile(presentationName); | |
string updatedFileName = "UpdatedPresentation.pptx"; | |
using (var fileStream = new FileStream(updatedFileName, FileMode.Create, FileAccess.Write)) | |
{ | |
updatedPresentationStream.CopyTo(fileStream); | |
} | |
Console.WriteLine($"Presentation saved as '{updatedFileName}'."); | |
} | |
} | |
} |
このコードは、C# REST インターフェイスを使用した Smart Art グラフィック をスライドに挿入する方法を示します。 LayoutEnum を使用して、AccentProcess、AccentedPicture、ArrowRibbon、BasicPyramid、BasicProcess などの値の大きなリストから目的の SmartArt 図形を選択します。同様に、クイック スタイル列挙子とカラー スタイル列挙子にも、SmartArt をカスタマイズするためのさまざまなオプションがあります。
この記事では、プレゼンテーション スライドで SmartArt を作成する方法を説明しました。プレゼンテーションにカスタム図形を追加する場合は、C# REST API を使用して PowerPoint でカスタム図形を作成する の記事を参照してください。