Skip to content

Commit

Permalink
Add sample for Word add-in using .NET 6
Browse files Browse the repository at this point in the history
  • Loading branch information
jozefizso committed Jun 9, 2024
1 parent f2ba193 commit 5084d3d
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Examples/Word/WordAddinCore/Addin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using NetOffice.Tools;
using NetOffice.WordApi.Tools;

namespace WordAddinCore
{
[ComVisible(true)]
[Guid("44408BE8-1C1A-4E80-93A5-3FE1B54B4384")]
[ProgId("NetOfficeSamples.WordAddinCore")]
public class Addin : COMAddin
{
public Addin()
{
OnStartupComplete += Addin_OnStartupComplete;
OnDisconnection += Addin_OnDisconnection;
}

private void Addin_OnStartupComplete(ref Array custom)
{
var appName = this.Application.Name;
var appVersion = this.Application.Version;
var appBuild = this.Application.Build;
Trace.WriteLine($"Addin connected to {appName} version {appVersion} ({appBuild}).");
}

private void Addin_OnDisconnection(ext_DisconnectMode removeMode, ref Array custom)
{
Trace.WriteLine($"Addin will shutdown.");
}
}
}
8 changes: 8 additions & 0 deletions Examples/Word/WordAddinCore/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"Word 32-bit": {
"commandName": "Executable",
"executablePath": "C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\WINWORD.EXE"
}
}
}
15 changes: 15 additions & 0 deletions Examples/Word/WordAddinCore/WordAddinCore.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnableComHosting>true</EnableComHosting>
<Platforms>x86;x64</Platforms>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Source\Word\WordApi.csproj" />
</ItemGroup>

</Project>
31 changes: 31 additions & 0 deletions Examples/Word/WordAddinCore/WordAddinCore.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33516.290
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WordAddinCore", "WordAddinCore.csproj", "{A3A7189F-3D99-47F7-A451-ECC7003744E6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WordApi", "..\..\..\Source\Word\WordApi.csproj", "{260973C4-E060-4007-B264-9886B793646E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A3A7189F-3D99-47F7-A451-ECC7003744E6}.Debug|Any CPU.ActiveCfg = Debug|x86
{A3A7189F-3D99-47F7-A451-ECC7003744E6}.Debug|Any CPU.Build.0 = Debug|x86
{A3A7189F-3D99-47F7-A451-ECC7003744E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A3A7189F-3D99-47F7-A451-ECC7003744E6}.Release|Any CPU.Build.0 = Release|Any CPU
{260973C4-E060-4007-B264-9886B793646E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{260973C4-E060-4007-B264-9886B793646E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{260973C4-E060-4007-B264-9886B793646E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{260973C4-E060-4007-B264-9886B793646E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6F19A0F2-ADA1-417B-8035-646401EFB9FF}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions Examples/Word/WordAddinCore/register.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
C:\Windows\SysWOW64\regsvr32.exe /s WordAddinCore.comhost.dll
:: C:\Windows\System32\regsvr32.exe /s WordAddin.comhost.dll

reg add "HKEY_CURRENT_USER\Software\Microsoft\Office\Word\Addins\NetOfficeSamples.WordAddinCore" /f /v LoadBehavior /t REG_DWORD /d 3
reg add "HKEY_CURRENT_USER\Software\Microsoft\Office\Word\Addins\NetOfficeSamples.WordAddinCore" /f /v FriendlyName /t REG_SZ /d "Word Addin (.NET 6)"
reg add "HKEY_CURRENT_USER\Software\Microsoft\Office\Word\Addins\NetOfficeSamples.WordAddinCore" /f /v Description /t REG_SZ /d "Sample addin running in .NET 6"

0 comments on commit 5084d3d

Please sign in to comment.