C# を使用して PPTX でテキストに取り消し線を引く方法

この簡単な例では、C# を使用して PPTX 内のテキストに取り消し線を引く方法を説明します。これには、必要なリソース、段階的な手順、c# を使用して PPTX テキストを取り消すための実際のサンプル コードに関する情報が含まれています。サンプル プレゼンテーションの作成、オートシェイプの追加、テキストの追加によるテキスト フレームの作成、テキストのストロークなどのプロセスの詳細が共有されます。

C# を使用して PPTX でテキストに取り消し線を付ける手順

  1. PPTX のテキストに取り消し線を付けるための Aspose.Slides for .NET を追加する環境を構成する
  2. Presentation クラスのインスタンスを使用してデフォルトの空のプレゼンテーションを作成し、最初のスライドにアクセスします
  3. 長方形タイプの自動シェイプを作成し、その中にサンプル テキスト フレームを追加します
  4. テキスト フレーム内にテキストの一部を追加し、TextStrikethroughType 列挙子を使用して二重線の取り消し線を設定します。
  5. テキスト フレーム内にテキストの 2 番目の部分を追加し、TextStrikethroughType 列挙子を使用して 1 行の取り消し線を設定します。
  6. PPTX に取り消し線付きのテキストを付けてプレゼンテーションを保存します。

前述の手順では、C# を使用してプレゼンテーション内のテキストに取り消し線を引く方法を説明しています。必要なクラス、メソッド、プロパティはすべて指定され、明確に定義された順序で使用され、空の PPTX ファイルの作成または既存の PPTX ファイルのロードには Presentation クラスが使用され、オートシェイプの追加には ShapeCollection クラスが使用されます。 PPTX スライドでは、TextStrikethroughType 列挙子を使用して、テキストの選択された部分に必要な取り消し線の種類を設定します。

C# を使用して PPTX でテキストを取り消すコード

using System;
using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;
namespace TestSlides
{
public class StrikeThroughText
{
public static void StrikeText()
{
String path = @"/Users/KnowledgeBase/TestData/";
//Setting the API linence
License SlidesLicense = new License();
SlidesLicense.SetLicense(path + "Conholdate.Total.Product.Family.lic");
//Instantiate a Presentation class object to create a presentation
using (Presentation presentation = new Presentation())
{
//Insert a Blank empty slide inside the presentation
ISlide slide = presentation.Slides.AddEmptySlide(presentation.LayoutSlides.GetByType(SlideLayoutType.Blank));
//Add a new autoshape of the Rectangle type
IAutoShape autoShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 0, 120, 300, 300);
// Filling the shape with no fill color
autoShape.FillFormat.FillType = FillType.NoFill;
//Add the text frame inside the autoshape
ITextFrame textFrame = autoShape.AddTextFrame("This is sample strikethrough text");
// Set the textual properties on the portion
IPortionFormat portionFormat = textFrame.Paragraphs[0].Portions[0].PortionFormat;
portionFormat.FillFormat.FillType = FillType.Solid;
portionFormat.FillFormat.SolidFillColor.Color = Color.Red;
//Strikethrough with a double line
portionFormat.StrikethroughType = TextStrikethroughType.Double;
//Add a second line of text inside the shape
IPortion secondPortion = new Portion("Second text line ");
textFrame.Paragraphs[0].Portions.Add(secondPortion);
portionFormat = secondPortion.PortionFormat;
portionFormat.FillFormat.FillType = FillType.Solid;
portionFormat.FillFormat.SolidFillColor.Color = Color.Blue;
//Strikethrouh with a single line
portionFormat.StrikethroughType = TextStrikethroughType.Single;
// Save the presentation with strikethrough text on the disk
presentation.Save(path + "StrikethroughText.pptx", SaveFormat.Pptx);
}
}
}
}

上記の例は、c#* を使用した PPT 内の *取り消し線テキストを示しています。 Presentation クラス オブジェクトを使用してデフォルトの空のプレゼンテーションを作成し、Presentation.Slides プロパティを使用してスライド コレクションの最初のデフォルト スライドにアクセスします。 Rectangle タイプのオートシェイプが作成され、その中にテキストが追加されます。最後に、TextStrikethroughType 列挙子を使用して、必要なテキスト取り消し線が設定され、取り消し線テキストを含むプレゼンテーションがディスクに保存されます。

このチュートリアルでは、C# を使用してプレゼンテーション テキストに取り消し線を引く方法を説明しました。プレゼンテーション内でスライドを結合するプロセスについて知りたい場合は、C# でスライドを結合する方法 の記事を参照してください。

 日本語