VSTO the PowerPoint (PPT) plug-in development common API Summary

About VSTO

VSTO ( Visual Studio Tools for Office ) is an alternative to VBA, making the development of Office applications easier to develop and use VSTO office applications can use the memory management functions, and many CLR Visual studio development environment provided, garbage collection and other functions

amount. . . This is Baidu's introduction, the manual funny! White said the office is used to develop plug-ins.

Office plug-in development solution of choice

Recently due to work, have been watching the development of solutions from Office plug-defined, there are several in total

  • Of a macro language VBA --- Visual Basic, and basically gave consideration
  • VSTO --- VB alternative to the current mainstream office plug-in implementation
  • Office add-ins --- using mainstream web technologies (HTML, CSS, and JavaScript) to operate the office documents

I said here last chose to use VSTOto implement demand. First of all VBAmust have been ruled out, it would not VB. Then Office add-insdue to its own characteristics so it is not in line with the demand to give up, the next presentation Office add-insis what a thing.

Use Visual Studio 2017to create a Office add-insproject, the system automatically creates a solution that contains two projects. ( Portal )




project description
Load project It contains only XML manifest file that contains descriptions of all settings add-ins. These settings can help determine when to activate the host Office add-ins and add-ons position should be displayed.
Web Application Project Content page contains add-ins, all of the files and documents required including the development of HTML and JavaScript support Office page references. In the development of add-ons, Visual Studio will host Web applications on the local IIS server. When ready to release add-ons, you need this project to deploy a Web application to a Web server.

This means that the user interface plug-ins are through the Http acquisition request to the server, and if there are some features (such as unified font, export, pictures, etc.) is required can also run offline, that this solution would not be able to meet. So finally I chose VSTO .

VSTO development of plug-in API Introduction PPT

At first I just wanted to open an article recording at those API development process commonly used (really easy to find ah!), And finally verbose pull a lot of background information, and finally turn things I wanted to record, and later, the students hope to develop step on pit smooth some.

Acquiring operation target common API

//获取当前ppt中所有的幻灯片
Globals.ThisAddIn.Application.ActivePresentation.Slides;
//获取当前选中的ppt幻灯片
var activeSlide = (Slide)Globals.ThisAddIn.Application.ActiveWindow.View.Slide;
//获取当前选中幻灯片的Index,默认从1开始
activeSlide.SlideIndex
//在当前选中幻灯片前插入新的幻灯片--代码提示中没有F12进去才找到的方法
slides.Add(activeSlide.SlideIndex, PpSlideLayout.ppLayoutCustom);
//获取当前窗体中的选定对象
Globals.ThisAddIn.Application.ActiveWindow.Selection;

Copy and paste operations slideshow

//选择复制的silde(可以为数组new int[2]{3,5}})
Globals.ThisAddIn.Application.ActivePresentation.Slides.Range(1).Copy();
//在指定位置粘贴slide
Globals.ThisAddIn.Application.ActivePresentation.Slides.Paste(1);

//复制别的文档中的slide
//在1位置插入指定路径ppt的Index 2-5的幻灯片
Globals.ThisAddIn.Application.ActivePresentation.Slides.InsertFromFile("c:\ppt\sales.ppt", 1, 2, 5);

Modify theme fonts (unified font capabilities)

//获取主题
var master = Globals.ThisAddIn.Application.ActivePresentation.SlideMaster;

//修改中文字体
//“标题”中的中文字体
master.Theme.ThemeFontScheme.MajorFont.Item(Microsoft.Office.Core.MsoFontLanguageIndex.msoThemeEastAsian).Name = "新宋体";
//“内容”中的中文字体
master.Theme.ThemeFontScheme.MinorFont.Item(Microsoft.Office.Core.MsoFontLanguageIndex.msoThemeEastAsian).Name = "新宋体";

//修改英文字体
//“标题”中的英文字体
master.Theme.ThemeFontScheme.MajorFont.Item(Microsoft.Office.Core.MsoFontLanguageIndex.msoThemeLatin).Name = "新宋体";
//“内容”中的英文字体
master.Theme.ThemeFontScheme.MinorFont.Item(Microsoft.Office.Core.MsoFontLanguageIndex.msoThemeLatin).Name = "新宋体";

Insert Picture

//在当前选中幻灯片左上角插入图片,位置和大小可以调整
//activeSlide看我上面的获取方式
//picUrl可以是网络地址或本机物理地址
activeSlide.Shapes.AddPicture(picUrl, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoTrue, 0, 0);

//选中一个文本框或图片框,插入背景图片
//获取第一个选中的“形状”
var shape = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange[0];
sharp.Fill.UserPicture(picUrl);

To be continued! (In fact, I was still groping them, then will organize a CommonHelper method, commonly used to obtain the package about the object API.)

Guess you like

Origin www.cnblogs.com/cplemom/p/11290688.html