首先在按插件之前农猬,我們需要做的是:
- 第一步:安裝Visual Studio庶柿。
https://www.visualstudio.com/zh-hans/downloads/?utm_source=mscom&utm_campaign=msdocs
安裝步驟簡(jiǎn)單易操作看铆,你只需要在安裝前選中以下幾個(gè)模塊:
選中這三個(gè)
下滑再選中這個(gè)
注意:如果你安裝的Visual Studio是2017版挤巡,那你的office就要是2016版剩彬;如果你安裝的Visual Studio是2010版,那么你的office就要是2010或者2007版矿卑。 - 第二步:安裝office喉恋。
開始以下步驟操作:
- 打開visual Studio后,點(diǎn)擊文件 ->新建 ->項(xiàng)目 ->按下面圖片選擇 ->可修改名稱 ->完成
選擇
-
完成后母廷,你會(huì)在你新建的項(xiàng)目路徑下發(fā)現(xiàn)以下幾個(gè)文件:
文件 -
新建項(xiàng)目之后打開開始寫代碼轻黑。
截圖一部分
下面為完整代碼,用的c#語(yǔ)言琴昆,部分都會(huì)有注釋:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using System.Text;
using System.Xml.Linq;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace demo1
{
public partial class ThisAddIn
{
int a = 0;
void Application_SlideShowBegin(SlideShowWindow Wn) // 開始播放
{
MessageBox.Show("hello.");
}
void Application_SlideShowNextSlide(SlideShowWindow Wn) //翻頁(yè)播放
{
a++;
String str = String.Format("no. {0}", a);
MessageBox.Show(str);
}
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.SlideShowBegin += new EApplication_SlideShowBeginEventHandler(Application_SlideShowBegin);
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
this.Application.SlideShowNextSlide += new EApplication_SlideShowNextSlideEventHandler(Application_SlideShowNextSlide);
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
點(diǎn)擊生成 ->重新生成解決方案
-
點(diǎn)擊生成 ->發(fā)布 ->下一步 ->完成
點(diǎn)擊下一步 -
在寫完代碼后:用Ctrl+f5打開PowerPoint氓鄙,播放PPT,你會(huì)看到彈出一個(gè)窗口业舍。
image.png -
查看加載項(xiàng)會(huì)出現(xiàn)你的項(xiàng)目:
image.png
出現(xiàn)加載項(xiàng)就說明已成功運(yùn)行抖拦,簡(jiǎn)單的小插件就好了升酣!