gpt4 book ai didi

c# - 如何从一组PPTS中复制特定的幻灯片?

转载 作者:行者123 更新时间:2023-11-30 16:03:01 26 4
gpt4 key购买 nike

我有一个应用程序可以根据某些条件识别一些幻灯片,并希望将这些幻灯片复制到一个 PPTX 文件中。我有用于复制幻灯片的 openxml 代码,它工作得很好,但是当输出文件大小增加时会花费太多时间。所以我决定转向互操作来应对。以下代码用于应对幻灯片。

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);

在这两种情况下,内容都被复制,但幻灯片的背景和格式在输出中消失了。在应对过程中有什么我想补充的吗。

最佳答案

using PPT = Microsoft.Office.Interop.PowerPoint;

public void Main()
{
PPT.Application app = new PPT.Application();
app.Visible = MsoTriState.msoCTrue;
PPT.Presentation ppt1 = app.Presentations.Open(@"C:\Presentation1.pptx");
ppt1.Slides[1].Copy();

PPT.Presentation ppt2 = app.Presentations.Open(@"C:\Presentation2.pptx");
ppt2.Windows[1].View.GotoSlide(1);

app.CommandBars.ExecuteMso("PasteSourceFormatting");

}

你可以试试这个。

关于c# - 如何从一组PPTS中复制特定的幻灯片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36997193/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com