1
私はいくつかの基準でいくつかのスライドを識別し、それらのスライドを単一のPPTXファイルにコピーしたいアプリケーションを持っています。私はコピースライドのためのopenxmlコードを持っていますが、それは完璧に動作しますが、出力ファイルサイズが大きくなると時間がかかりすぎます。だから私は対処するためにinteropに移動することを決めた。次のコードは、スライドに対処するためのコードです。PPTSのグループから特定のスライドをコピーする方法は?
using Microsoft.Office.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
namespace CloneSlide
{
class Program
{
static void Main(string[] args)
{
try
{
PowerPoint.Application app = new PowerPoint.Application();
PowerPoint.Presentation currPresentation = null;
PowerPoint.Presentation currPresentationop = null;
string inputFileName = @"C:\Users\user\Desktop\Blannkdocs\ppt\Input.pptx";
//PowerPoint.Presentations presentations = app.Presentations;
//var readOnly = Microsoft.Office.Core.MsoTriState.msoTrue;
//var untitled = Microsoft.Office.Core.MsoTriState.msoTrue;
//var withwindow = Microsoft.Office.Core.MsoTriState.msoFalse;
//string chkfileforpassword = inputFileName + "::" + "\"\"" + "::" + "\"\"";
//currPresentation = presentations.Open(chkfileforpassword, readOnly, untitled, withwindow);
//currPresentation.Slides[1].Copy();
string outputFileName = @"C:\Users\user\Desktop\Blannkdocs\ppt\Presentation1.pptx";
PowerPoint.Presentations presentationsop = app.Presentations;
currPresentationop = presentationsop.Open(outputFileName, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
//currPresentationop.Slides.Paste(1);
currPresentationop.Slides.InsertFromFile(inputFileName, 1, 1, 1);
System.Threading.Thread.Sleep(4000);
currPresentationop.Save();
app.Quit();
}
catch (Exception exp)
{
Console.WriteLine(exp);
}
Console.WriteLine("Execution Complete");
Console.ReadLine();
}
}
}
私はすでにケースコンテンツの両方に
//currPresentationop.Slides.Paste(1);
currPresentationop.Slides.InsertFromFile(inputFileName, 1, 1, 1);
で試してみましたがコピーされますが、スライドの背景や書式は、出力に姿を消しました。私が対処している間に追加したくなかったものはありますか?
PublishSlidesメソッドが役立つかもしれませんが、信頼性が高いとは思いませんでした。最も簡単なのは、プレゼンテーションの新しいコピーを保存してから、含めたくないスライドを削除することです(常に先頭から最後まで)。 –
また、挿入したスライドにソースデザインを適用することもできます。 –