私は.NETが初めてです。.pptx ファイルを .wmv に変換するコンソール アプリケーションを作成したいと考えています。Powerpoint 相互運用機能を使用してこれを行うことができましたが、いくつか問題があります。まず、アプリケーションをビルドして別のコンピューターに転送すると、 COMオブジェクトに対して例外エラーHRESULT E_FAILが返されました(両方のPCにパワーポイントがあります)。書いたもので実行すると、すべて正常に動作します。しかし、初めてではありません。つまり、PCを起動して実行すると同じ例外が発生し、2 回目に実行しようとすると正しく実行されます。何が問題なのですか?相互運用機能とパワーポイントで何かを推測しますが、わかりません。
ここにコードがあります:
using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using System.Runtime.InteropServices;
using System.IO;
using System;
namespace Microsoft.Office.Interop.PowerPoint
{
class Program
{
static void Main(string[] args)
{
string fileName = args[0];
string exportName = args[1];
string exportPath = args[2];
Microsoft.Office.Interop.PowerPoint.Application ppApp = new Microsoft.Office.Interop.PowerPoint.Application();
ppApp.Visible = MsoTriState.msoTrue;
ppApp.WindowState = PpWindowState.ppWindowMinimized;
Microsoft.Office.Interop.PowerPoint.Presentations oPresSet = ppApp.Presentations;
Microsoft.Office.Interop.PowerPoint._Presentation oPres = oPresSet.Open(fileName,
MsoTriState.msoFalse, MsoTriState.msoFalse,
MsoTriState.msoFalse);
try
{
oPres.CreateVideo(exportName);
oPres.SaveCopyAs(String.Format(exportPath, exportName),
PowerPoint.PpSaveAsFileType.ppSaveAsWMV,
MsoTriState.msoCTrue);
}
finally
{
ppApp.Quit();
}
}
}
}