1

我正在制作一个C# 应用程序,我创建了powerpoint 演示文稿。我希望以编程方式将主题应用于我的演示文稿。我使用以下代码获得了主题列表。但是我怎样才能将它们应用到一个活跃的演示文稿中呢?

String programfilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
String msOfficePath = "Microsoft Office\\Document Themes 14";
String fullPath = Path.Combine(programfilesPath, msOfficePath);
String[] fileEntries = Directory.GetFiles(fullPath, "*.thmx", SearchOption.TopDirectoryOnly);

知道如何进行吗?

4

2 回答 2

1

我刚刚找到了一些很好的例子:

  1. 以编程方式创建 PowerPoint
  2. 应用主题 PowerPoint 2010

结合这两个指南时,这一切都归结为

using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Core = Microsoft.Office.Core;
// ...

// create application object
PowerPoint.Application pptApplication = new PowerPoint.Application();

PowerPoint.Slides slides;
PowerPoint._Slide slide;
PowerPoint.TextRange objText;

// Create the Presentation File
PowerPoint.Presentation pptPresentation = pptApplication.Presentations.Add(Core.MsoTriState.msoTrue);

// APPLY THEME - for example Clarity.thmx or 
// anything within Microsoft Office\Document Themes 14    
pptPresentation.ApplyTheme(@"C:\Program Files (x86)\Microsoft Office\Document Themes 14\Clarity.thmx");

PowerPoint.CustomLayout customLayout = pptPresentation.SlideMaster.CustomLayouts[PowerPoint.PpSlideLayout.ppLayoutText];

// Create new Slide
slides = pptPresentation.Slides;
slide = slides.AddSlide(1, customLayout);

// Add title, modify content and so on ...
objText = slide.Shapes[1].TextFrame.TextRange;
objText.Text = "hello world";
objText.Font.Name = "Verdana";

pptPresentation.SaveAs(@"c:\yourPPT.pptx", PowerPoint.PpSaveAsFileType.ppSaveAsDefault, Core.MsoTriState.msoTrue);

pptPresentation.Close();
pptApplication.Quit();
GC.Collect();
于 2013-01-16T21:35:18.803 回答
0

找到了我正在寻找的答案,我正在分享完整的代码以帮助他人

using Microsoft.Office.Interop.PowerPoint;

String programfilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
String msOfficePath = "Microsoft Office\\Document Themes 14";
String fullPath = Path.Combine(programfilesPath, msOfficePath);
String themePresentationPath = fullPath + "\\" + Waveform.thmx"; 
// You can change this Waveform.thmx file to any other theme file to apply other theme.


Application pptApplication = new Application();
Presentation pptPresentation = pptApplication.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue);

pptPresentation.ApplyTemplate(themePresentationPath);
于 2013-01-16T21:34:56.403 回答