我正在创建一个 C#应用程序来创建 powerpoint presentation 。我希望以编程方式将主题应用于我的演示文稿。我使用以下代码获得了主题列表。但是我怎样才能在活跃的演示文稿中应用它们呢?
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);
知道如何继续吗?
答案 0 :(得分:1)
我刚刚找到了一些很好的例子:
当组合这两个指南时,所有这些都来到了这个
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();
答案 1 :(得分: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);