透かしなしで本番環境でテストしてください。
必要な場所で動作します。
30日間、完全に機能する製品をご利用いただけます。
数分で稼働させることができます。
製品トライアル期間中にサポートエンジニアリングチームへの完全アクセス
ソフトウェア開発の分野では、PowerPointプレゼンテーションを画像形式に変換する必要性が頻繁に発生します。 多くの開発者は、プレビューの生成、サムネイルの作成、システム統合のために、PowerPointファイルをプログラムで写真に変換できることが便利であると感じています。 この記事では、C#を使用してPPTを画像に変換する方法を説明し、その過程で役立ついくつかのサンプルコードを含めます。
PowerPointアプリケーションインスタンスを作成します。
インスタンスを使用してプレゼンテーションを開く。
出力フォルダを確認して作成します。
スライドを繰り返し処理し、スライドを画像にエクスポート。
具体的な内容に入る前に、PowerPointスライドを写真に変換することの重要性について簡単に見てみましょう。 PowerPointはダイナミックなプレゼンテーションを作成するための優れたツールですが、これらのファイルを元の形式のまま共有することが常に可能であるとは限りません。 時には、プレゼンテーションから特定のスライドや写真だけが必要な場合があり、また別のシステムや設定ではPowerPointファイルの直接レンダリングができないことがあります。 PowerPointプレゼンテーションを画像に変換することで、さまざまなデバイスやアプリケーションで簡単に共有・閲覧できる包括的なソリューションを提供します。
PowerPoint プレゼンテーションを C# で画像に変換するためのいくつかの方法があります。 Microsoft.Office.Interop.PowerPoint 名前空間を使用することは、PowerPoint アプリケーションとプログラムでインターフェースするためのクラスとメソッドを提供する一般的なアプローチの一つです。 PowerPointファイルを扱うための幅広い機能を提供します。
新しいVisual Studioプロジェクトを作成するには、以下の手順に従ってください:
Visual Studio IDEを開きます。使用する前にPCにVisual Studioをインストールしていることを確認してください。
新しいプロジェクトを開始する:
「ファイル」、「新規作成」、そして最後に「プロジェクト」を選択してください。
「新しいプロジェクトを作成」ボックスから、左側にあるお好みのプログラミング言語(たとえばC#)を選択します。
次に、利用可能なプロジェクトテンプレートのリストから「Console App」または「Console App (.NET Core)」テンプレートを選択します。
「名前」欄を埋めて、プロジェクトに名前を付けてください。
プロジェクトの保存場所を選択してください。
「作成」をクリックして、新しいコンソールアプリケーションプロジェクトの作業を開始します。
Microsoft.Office.Interop.PowerPoint名前空間を使用してPowerPointスライドを画像に変換する方法を見てみましょう。 必要なアセンブリがインストールされ、まずC#プロジェクトにリファレンスとして追加されていることを確認してください。これらのアセンブリは通常、Interopアセンブリを直接参照するか、Microsoft Office Primary Interop Assemblies(PIA)をインストールすることで見つかります。
using System.IO;
using Microsoft.Office.Interop.PowerPoint;
class Program
{
static void Main(string [] args)
{
string pptFilePath = "demo.pptx"; // Path to your PowerPoint file
string outputFolder = "output_images"; // Output folder path where images will be saved
ConvertPptToImages(pptFilePath, outputFolder);
}
static void ConvertPptToImages(string pptFilePath, string outputFolder)
{
Application pptApplication = new Application();
Presentation pptPresentation = pptApplication.Presentations.Open(pptFilePath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
if (!Directory.Exists(outputFolder))
Directory.CreateDirectory(outputFolder);
int slidesCount = pptPresentation.Slides.Count;
for (int i = 1; i <= slidesCount; i++)
{
string outputPath = Path.Combine(outputFolder, $"Slide{i}.png");
pptPresentation.Slides[i].Export(outputPath, "png", 1024, 768);
//saving the presentation slides into png images
}
pptPresentation.Close();
pptApplication.Quit();
}
}
using System.IO;
using Microsoft.Office.Interop.PowerPoint;
class Program
{
static void Main(string [] args)
{
string pptFilePath = "demo.pptx"; // Path to your PowerPoint file
string outputFolder = "output_images"; // Output folder path where images will be saved
ConvertPptToImages(pptFilePath, outputFolder);
}
static void ConvertPptToImages(string pptFilePath, string outputFolder)
{
Application pptApplication = new Application();
Presentation pptPresentation = pptApplication.Presentations.Open(pptFilePath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
if (!Directory.Exists(outputFolder))
Directory.CreateDirectory(outputFolder);
int slidesCount = pptPresentation.Slides.Count;
for (int i = 1; i <= slidesCount; i++)
{
string outputPath = Path.Combine(outputFolder, $"Slide{i}.png");
pptPresentation.Slides[i].Export(outputPath, "png", 1024, 768);
//saving the presentation slides into png images
}
pptPresentation.Close();
pptApplication.Quit();
}
}
Imports System.IO
Imports Microsoft.Office.Interop.PowerPoint
Friend Class Program
Shared Sub Main(ByVal args() As String)
Dim pptFilePath As String = "demo.pptx" ' Path to your PowerPoint file
Dim outputFolder As String = "output_images" ' Output folder path where images will be saved
ConvertPptToImages(pptFilePath, outputFolder)
End Sub
Private Shared Sub ConvertPptToImages(ByVal pptFilePath As String, ByVal outputFolder As String)
Dim pptApplication As New Application()
Dim pptPresentation As Presentation = pptApplication.Presentations.Open(pptFilePath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse)
If Not Directory.Exists(outputFolder) Then
Directory.CreateDirectory(outputFolder)
End If
Dim slidesCount As Integer = pptPresentation.Slides.Count
For i As Integer = 1 To slidesCount
Dim outputPath As String = Path.Combine(outputFolder, $"Slide{i}.png")
pptPresentation.Slides(i).Export(outputPath, "png", 1024, 768)
'saving the presentation slides into png images
Next i
pptPresentation.Close()
pptApplication.Quit()
End Sub
End Class
C# 名前空間を使用して PowerPoint アプリを操作するには、Microsoft.Office.Interop.PowerPoint;
宣言を使用してインポートします。 プログラムのエントリーポイントはMain
メソッドです。 それは、作成された写真が保存される出力フォルダー (outputFolder
) と、PowerPointファイルへのパス (pptFilePath
) を指定します。 PowerPointプレゼンテーションの実際の写真への変換は、この方法で処理されます。
Application pptApplication = new Application();
はPowerPointプログラムの新しいインスタンスを開始するために使用されます。 これにより、PowerPointを使用したプログラムによる対話が可能になります。 pptApplication.Presentations
を使用して、pptFilePath.Open()
関数で指定されたPowerPointプレゼンテーションファイルを開きます。 この関数は、開いたプレゼンテーションを表すPresentationオブジェクトを返します。 出力フォルダ「outputFolder
」が存在するかどうかを判断します。 そうでない場合は、Directory.CreateDirectory()
メソッドを使用して作成します。
プレゼンテーション内の各スライドを反復処理するために、forループを使用します。 pptPresentation
は、プロパティSlides.Count
を使用してスライドの総数を提供します。 出力フォルダパスとスライドインデックスを使用して、各スライドの画像の出力パスを作成します(例:Slides{i}.png
)。 次に、pptPresentation
を使用して、Export()
関数を使い、PowerPointスライドを画像としてエクスポートします(この例では、JPG画像、PNG画像形式)。 パラメータは画像形式(「png」形式)とサイズ(幅:1024、高さ:768)です。 最後に、プレゼンテーションを終了するためにpptPresentation
を使用します。 Close()を使用して、pptApplication
でPowerPointセッションを終了します。 システムリソースを適切に解放するには、Quit()
を使用してください。
人気のある .NET フレームワークIronXLは、C#でExcelファイルを操作するのを簡単にします。 多数の機能を備えたExcelファイルの読み取り、作成、および編集が可能なため、幅広い用途に適した柔軟なツールです。 以下に、IronXLの主な機能のいくつかを紹介します:
IronXLはExcelスプレッドシートの個々のセルを正確に操作することが可能です。 プログラムによって、開発者は書式設定、スタイル、数式、セルの値、およびその他の特性を設定することができます。
ドキュメントの詳細については、IronXL Documentationを参照してください。
次に進む前に、NuGet パッケージ マネージャ コンソールを使用して IronXL をインストールしましょう:
Install-Package IronXL.Excel
インストール後、IronXLはC#プロジェクトで使用できます。
仮想の状況を検討してみましょう。IronXLを使用してExcelファイルからデータを読み取りたいとします。
次のコード・サンプルで、これを達成する方法を簡単に説明します:
using IronXL;
using System;
class Program
{
static void Main(string [] args)
{
// Path to the Excel file
string excelFilePath = "sample.xlsx";
// Load the Excel file
WorkBook workbook = WorkBook.Load(excelFilePath);
// Access the first worksheet
WorkSheet worksheet = workbook.WorkSheets[0];
// Iterate through rows and columns to read data
foreach (var row in worksheet.Rows)
{
foreach (var cell in row)
{
Console.Write(cell.Value + "\t");
}
Console.WriteLine();
}
}
}
using IronXL;
using System;
class Program
{
static void Main(string [] args)
{
// Path to the Excel file
string excelFilePath = "sample.xlsx";
// Load the Excel file
WorkBook workbook = WorkBook.Load(excelFilePath);
// Access the first worksheet
WorkSheet worksheet = workbook.WorkSheets[0];
// Iterate through rows and columns to read data
foreach (var row in worksheet.Rows)
{
foreach (var cell in row)
{
Console.Write(cell.Value + "\t");
}
Console.WriteLine();
}
}
}
Imports Microsoft.VisualBasic
Imports IronXL
Imports System
Friend Class Program
Shared Sub Main(ByVal args() As String)
' Path to the Excel file
Dim excelFilePath As String = "sample.xlsx"
' Load the Excel file
Dim workbook As WorkBook = WorkBook.Load(excelFilePath)
' Access the first worksheet
Dim worksheet As WorkSheet = workbook.WorkSheets(0)
' Iterate through rows and columns to read data
For Each row In worksheet.Rows
For Each cell In row
Console.Write(cell.Value & vbTab)
Next cell
Console.WriteLine()
Next row
End Sub
End Class
まず、必要な名前空間を含めます。 IronXLライブラリが提供するクラスとメソッドは、IronXL名前空間に含まれています。 読み込みたいExcelファイル(sample.xlsx)のパスが指定されています。 WorkBook はExcelファイルをロードするために使用されます。Excelワークブックは、Load() 関数によって返される WorkBook オブジェクトによって表されます。 ワークブックを使用すると、workbook.WorkSheets[0]
を使用して最初のワークシートにアクセスできます。 ネストされた foreach ループを使用して、ワークシートの行と列を走査します。 各セルの値をコンソールに出力します。
コードの詳細については、IronXL Read Excel Examplesを参照してください。
多くのソフトウェアアプリケーションでは、C#を使用してPowerPointプレゼンテーションを写真に変換する必要があります。 Microsoft.Office.Interop.PowerPoint 名前空間を使用するかしないかに関係なく、手順は比較的迅速に完了できます。 この記事のコード例は、C#アプリにPowerPointから画像への変換機能を簡単に組み込む方法を提供し、情報の配布と変更の多くの機会を創出します。
ターゲットマシンにExcelをインストールする必要がなく、またはInteropライブラリに依存することなく、IronXLはC#でExcel操作を実行するための迅速で効果的な方法を提供します。 C#アプリケーションでExcelデータを処理するためにIronXLを使用する開発者は、ユーザーフレンドリーなAPIと広範な機能セットにより、Excelファイルの読み込み、書き込み、および変更といった操作が効率化されることを発見するでしょう。 IronXLは、レポートの作成、データの処理、またはスプレッドシートの作業の自動化にかかわらず、Excel関連の開発プロジェクトにおいて効率と柔軟性を向上させる信頼性の高いソリューションを提供します。
IronXLの無料トライアルには、広範な機能とサポートが含まれています。 ライセンスに関する包括的で最新の情報については、IronXL ライセンス情報をご覧ください。 Iron Softwareのウェブサイトを訪れて、Iron Softwareの製品について詳しく学んでください。