チュートリアル
簡単にライブラリーを使用するためのチュートリアルコレクション
PowerPoint プレゼンテーションには、オーディエンスを追加のリソースやプレゼンテーション内の別の場所に誘導するハイパーリンクが含まれていることがよくあります。これらのリンクは、追加情報を提供したり、簡単にナビゲートしたりするのに役立ちますが、プレゼンテーションの流れを妨げたり、プロフェッショナルな外観を損なう場合があります。スライド内の無効なリンクや不要なリンクを削除することで、プレゼンテーションの全体的な質を向上させることができます。
この記事では、C# プログラムで Spire.Presentation for .NET を使用して、PowerPoint プレゼンテーションからハイパーリンクを効率的に削除する方法を紹介します。
まず、Spire.Presentation for .NET パッケージに含まれている DLL ファイルを .NET プロジェクトの参照として追加する必要があります。DLL ファイルは、このリンクからダウンロードするか、NuGet を介してインストールできます。
PM> Install-Package Spire.Presentation
PowerPoint プレゼンテーションの通常のテキストは、自動シェイプ(AutoShape)に含まれています。開発者は、IAutoShape.TextFrame.Paragraphs[].TextRanges[] プロパティを使用してこれらのシェイプ内のテキスト範囲にアクセスし、TextRange.ClickAction プロパティを使用してハイパーリンクを読み取ったり設定したりすることができます。テキストのハイパーリンクは、TextRange.ClickAction プロパティを null に設定することで削除できます。
詳細な手順は次のとおりです:
using Spire.Presentation;
namespace RemoveSlideTextLink
{
class Program
{
public static void Main(string[] args)
{
// Presentationのインスタンスを作成し、PowerPointプレゼンテーションを読み込む
Presentation presentation = new Presentation();
presentation.LoadFromFile("Sample.pptx");
// プレゼンテーション内のスライドを繰り返し処理
foreach (ISlide slide in presentation.Slides)
{
// スライド内の図形を繰り返し処理
foreach (IShape shape in slide.Shapes)
{
// 現在の図形がIAutoShapeクラスのインスタンスかどうかを確認
if (shape is IAutoShape)
{
IAutoShape autoShape = (IAutoShape)shape;
// 図形内の段落を繰り返し処理
foreach (TextParagraph paragraph in autoShape.TextFrame.Paragraphs)
{
// 段落内のテキスト範囲を繰り返し処理
foreach (TextRange textRange in paragraph.TextRanges)
{
// テキスト範囲にハイパーリンクがあるかどうかを確認
if (textRange.ClickAction != null)
{
// ハイパーリンクを削除
textRange.ClickAction = null;
}
}
}
}
}
}
// プレゼンテーションを保存
presentation.SaveToFile("output/スライドテキストのハイパーリンクを削除.pptx", FileFormat.Auto);
presentation.Dispose();
}
}
}
IShape クラスは、スライド内のすべての種類のシェイプ(自動シェイプ、画像、テーブルなど)を表します。これらのすべてのシェイプ上のハイパーリンクは、IShape.Click プロパティを null に設定することで削除できます。詳細な手順は次のとおりです:
using Spire.Presentation;
namespace RemoveSlideShapeHyperlink
{
class Program
{
static void Main(string[] args)
{
// Presentationクラスのインスタンスを作成し、PowerPointプレゼンテーションを読み込む
Presentation presentation = new Presentation();
presentation.LoadFromFile("Sample.pptx");
// プレゼンテーション内のスライドを繰り返し処理
foreach (ISlide slide in presentation.Slides)
{
// スライド内の図形を繰り返し処理
foreach (IShape shape in slide.Shapes)
{
// 図形にハイパーリンクがあるかどうかを確認
if (shape.Click != null)
{
shape.Click = null;
}
}
}
// プレゼンテーションを保存
presentation.SaveToFile("output/スライドシェイプのハイパーリンクを削除.pptx", FileFormat.Auto);
presentation.Dispose();
}
}
}
すべてのシェイプから直接ハイパーリンクを削除するだけでなく、削除する前にシェイプの種類を判別し、指定された種類のシェイプからのみハイパーリンクを見つけて削除することもできます。詳細な手順は次のとおりです:
using Spire.Presentation;
using Spire.Presentation.Charts;
namespace RemoveSlideShapeTypeHyperlink
{
class Program
{
static void Main(string[] args)
{
// Presentationクラスのインスタンスを作成し、PowerPointプレゼンテーションを読み込む
Presentation presentation = new Presentation();
presentation.LoadFromFile("Sample.pptx");
// プレゼンテーション内のスライドを繰り返し処理
foreach (ISlide slide in presentation.Slides)
{
// スライド内の図形を繰り返し処理
foreach (IShape shape in slide.Shapes)
{
// 図形がIEmbedImage、ITable、またはIChartのインスタンスかどうかを確認
if (shape is IEmbedImage || shape is ITable || shape is IChart)
{
// シェイプにハイパーリンクがあるかどうかを確認
if (shape.Click != null)
{
// ハイパーリンクを削除
shape.Click = null;
}
}
}
}
// プレゼンテーションを保存
presentation.SaveToFile("output/スライドシェイプ型のハイパーリンクを削除.pptx", FileFormat.Auto);
presentation.Dispose();
}
}
}
テーブル内のテキストからハイパーリンクを削除するには、テーブルのセルと各セル内のテキスト範囲を繰り返し処理する必要があります。その後、各セル内のテキスト範囲にあるハイパーリンクを TextRange.ClickAction プロパティを null に設定することで削除できます。詳細な手順は次のとおりです:
using Spire.Presentation;
namespace RemoveSlideTableTextHyperlink
{
class Program
{
static void Main(string[] args)
{
// Presentationクラスのインスタンスを作成し、PowerPointプレゼンテーションを読み込む
Presentation presentation = new Presentation();
presentation.LoadFromFile("Sample.pptx");
// プレゼンテーション内のスライドを繰り返し処理
foreach (ISlide slide in presentation.Slides)
{
// スライド内の図形を繰り返し処理
foreach (IShape shape in slide.Shapes)
{
// 図形がITableのインスタンスかどうかを確認
if (shape is ITable)
{
ITable table = (ITable)shape;
// テーブル内の行を繰り返し処理
foreach (TableRow row in table.TableRows)
{
// 行内のセルを繰り返し処理
foreach (Cell cell in row)
{
// セル内の段落を繰り返し処理
foreach (TextParagraph paragraph in cell.TextFrame.Paragraphs)
{
// 段落内のテキスト範囲を繰り返し処理
foreach (TextRange textRange in paragraph.TextRanges)
{
// テキスト範囲にハイパーリンクがあるかどうかを確認
if (textRange.ClickAction != null)
{
// ハイパーリンクを削除
textRange.ClickAction = null;
}
}
}
}
}
}
}
}
// プレゼンテーションを保存
presentation.SaveToFile("output/スライドテーブルのテキストハイパーリンクを削除.pptx", FileFormat.Auto);
presentation.Dispose();
}
}
}
結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。
ハイパーリンクはクリック可能な要素であり、多くの場合テキストや画像に埋め込まれており、ユーザーがさまざまな Web ページ、ドキュメント、またはリソースに移動してアクセスするのに役立ちます。 PowerPoint プレゼンテーションにハイパーリンクを追加すると、ユーザーはスライドを表示またはプレゼンテーションするときに関連コンテンツに簡単にアクセスでき、プレゼンテーション プロセス中の利便性が向上します。この記事では、Spire.Presentation for .NET を使用して C# で PowerPoint プレゼンテーションにハイパーリンクを追加する方法を示します。
まず、Spire.Presentation for .NET パッケージに含まれている DLL ファイルを .NET プロジェクトの参照として追加する必要があります。DLL ファイルは、このリンクからダウンロードするか、NuGet を介してインストールできます。
PM> Install-Package Spire.Presentation
Spire.Presentation for .NET では、TextRange.ClickAction.Address プロパティを使用して、スライド上のテキストにハイパーリンクを簡単に挿入することができます。以下はその詳細な手順です。
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;
namespace Hyperlink
{
internal class Program
{
static void Main(string[] args)
{
//Presentationインスタンスを作成する
Presentation presentation = new Presentation();
//PowerPoint ファイルを読み込む
presentation.LoadFromFile("sample.pptx", FileFormat.Pptx2010);
//最初のスライドを取得する
ISlide slide = presentation.Slides[0];
//スライドに図形を追加する
RectangleF rec = new RectangleF(presentation.SlideSize.Size.Width / 2 - 120, 200, 500, 150);
IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle, rec);
shape.Fill.FillType = FillFormatType.None;
shape.ShapeStyle.LineColor.Color = Color.White;
//図形内のデフォルトの段落を削除する
shape.TextFrame.Paragraphs.Clear();
//TextParagraph インスタンスを作成する
TextParagraph para = new TextParagraph();
//TextRangeインスタンスを作成する
TextRange tr = new TextRange("Spire.Presentation for .NET");
//テキスト範囲のハイパーリンクアドレスを設定する
tr.ClickAction.Address = "https://jp.e-iceblue.com/introduce/spire-presentation-for-net.html";
//テキスト範囲を段落に追加する
para.TextRanges.Append(tr);
//TextRangeインスタンスを作成する
tr = new TextRange("は、開発者が .NETでPowerPoint文書を作成・読み込み・書き出し・変換・印刷するために設計された専門的な PowerPoint のライブラリです。"
+ "これは完全に独立したスタンドアロン API なので、Microsoft PowerPoint を実行環境にインストールする必要はありません。");
//テキスト範囲を段落に追加する
para.TextRanges.Append(tr);
//段落を図形に追加する
shape.TextFrame.Paragraphs.Append(para);
//図形内の段落をループする
foreach (TextParagraph textPara in shape.TextFrame.Paragraphs)
{
if (!string.IsNullOrEmpty(textPara.Text))
{
//各段落のテキスト範囲をループする
foreach (TextRange textRange in textPara.TextRanges)
{
//フォントを設定する
textRange.LatinFont = new TextFont("Yu Mincho");
textRange.FontHeight = 20;
textRange.Fill.FillType = FillFormatType.Solid;
textRange.Fill.SolidColor.Color = Color.Black;
}
}
}
//プレゼンテーションを保存する
presentation.SaveToFile("TextHyperlink.pptx", FileFormat.Pptx2013);
presentation.Dispose();
}
}
}
Spire.Presentation for .NET は、画像へのハイパーリンクの追加もサポートしています。ClickHyperlink クラスを使用してハイパーリンクを作成し、IEmbedImage.Click プロパティを使用してハイパーリンクを画像に追加できます。関連する手順は次のとおりです。
using Spire.Presentation;
using System.Drawing;
namespace ImageHyperlink
{
class Program
{
static void Main(string[] args)
{
//Presentationクラスのオブジェクトを初期化する
Presentation presentation = new Presentation();
//PowerPoint ファイルを読み込む
presentation.LoadFromFile("TextHyperlink.pptx", FileFormat.Pptx2010);
//2 番目のスライドを取得する
ISlide slide = presentation.Slides[1];
//スライドに画像を追加する
RectangleF rect = new RectangleF(100, 50, 150, 150);
IEmbedImage image = slide.Shapes.AppendEmbedImage(ShapeType.Rectangle, @"logo.png", rect);
//画像にハイパーリンクを追加する
ClickHyperlink hyperlink = new ClickHyperlink("https://jp.e-iceblue.com/introduce/spire-presentation-for-net.html");
image.Click = hyperlink;
//結果ファイルを保存する
presentation.SaveToFile("ImageHyperlink.pptx", FileFormat.Pptx2010);
presentation.Dispose();
}
}
}
結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。