我嘗試實作一個應用程式,它允許我將 PPT 或 PPTX 檔案轉換為 jpgs,我計劃在我的電腦上全域使用它。我面臨的問題是我不知道如何決議我在應用程式中打開的檔案。基本上,當我打開特定檔案時,我需要應用程式獲取完整路徑和檔案名,因此對某些特定路徑進行硬編碼是不可能的。
總體思路:我將一個 ppt 檔案拖到 .exe 檔案上,然后它處理 ppt 檔案,最后我有一個檔案夾,其中所有 jpg 與 ppt 位于同一位置。這是我到目前為止所擁有的:
using Microsoft.Office.Core;
using System;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
namespace PPInterop
{
class Program
{
static void Main(string[] args)
{
var app = new PowerPoint.Application();
var pres = app.Presentations;
var file = pres.Open(@"C:\presentation1.jpg", MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse);
file.SaveCopyAs(@"C:\presentation1.jpg", PowerPoint.PpSaveAsFileType.ppSaveAsJPG, MsoTriState.msoTrue);
Console.ReadKey();
}
}
}
uj5u.com熱心網友回復:
關于決議,我認為您已經找到了微軟通過使用來自Microsoft.Office.Interop.PowerPoint.
但是您正在加載 JPG 而不是 PPT 或 PPTX 檔案。拖放也應該是可能的,args因為(至少 Windows)將使用拖動的檔案作為引數運行應用程式(參見此處)。
所以我認為可能是這樣的:
static void Main(string[] args)
{
if (args.Length == 0)
throw new Exception("No presentation file given");
var presentationFilePath = new FileInfo(args[0]);
if (presentationFilePath.Exists == false)
throw new FileNotFoundException("No presentation given");
var app = new PowerPoint.Application();
var presentation = app.Presentations.Open(presentationFilePath, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse);
var jpgName = Path.GetFileNameWithoutExtension(presentationFilePath.FullName) ".jpg";
presentation.SaveCopyAs(jpgName, PowerPoint.PpSaveAsFileType.ppSaveAsJPG, MsoTriState.msoTrue);
Console.WriteLine("Converted " presentationFilePath " to " jpgName);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/473565.html
上一篇:決議Yaml檔案
