Skip to content

Commit 9f9e890

Browse files
committed
Added the ExcelDna.Interop NuGet package and added a command example to the C# project template.
1 parent 7e02a53 commit 9f9e890

7 files changed

Lines changed: 44 additions & 0 deletions

File tree

ExcelDNAVSExtension/CSProjectTemplate/CSProjectTemplate.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
</ItemGroup>
5656
<ItemGroup>
5757
<None Include="MyRibbon.cs" />
58+
<None Include="MyCommands.cs" />
5859
<Compile Include="Properties\AssemblyInfo.cs" />
5960
</ItemGroup>
6061
<ItemGroup>

ExcelDNAVSExtension/CSProjectTemplate/CSProjectTemplate.vstemplate

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<Project File="ProjectTemplate.csproj" ReplaceParameters="true">
2121
<ProjectItem ReplaceParameters="true" TargetFileName="Properties\AssemblyInfo.cs">AssemblyInfo.cs</ProjectItem>
2222
<ProjectItem ReplaceParameters="true" OpenInEditor="true">MyFunctions.cs</ProjectItem>
23+
<ProjectItem ReplaceParameters="true">MyCommands.cs</ProjectItem>
2324
<ProjectItem ReplaceParameters="true">MyRibbon.cs</ProjectItem>
2425
<ProjectItem ReplaceParameters="true" TargetFileName="RibbonResources\Ribbon.xml">Ribbon.xml</ProjectItem>
2526
<ProjectItem TargetFileName="RibbonResources\Image1.png">Image1.png</ProjectItem>
@@ -38,6 +39,7 @@
3839
<packages repository="extension" repositoryId="f1b3b55f-9bdc-4e9a-802c-84b329e36587">
3940
<package id="ExcelDna.Integration" version="1.1.0" />
4041
<package id="ExcelDna.AddIn" version="1.1.1" />
42+
<package id="ExcelDna.Interop" version="14.0.1" />
4143
</packages>
4244
</WizardData>
4345
</VSTemplate>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using ExcelDna.Integration;
2+
using Microsoft.Office.Interop.Excel;
3+
4+
namespace $safeprojectname$
5+
{
6+
public static class MyCommands
7+
{
8+
// We make a command macro that can be run by:
9+
// * Pressing the quick menu under the Add-ins tab
10+
// * Pressing the shortcut key Ctrl + Shift + D
11+
// * Typing the name into the Alt+F8 Macro dialog (add-in macros won't we shown on this list, though)
12+
[ExcelCommand(MenuName = "$projectname$", MenuText = "Dump Data", ShortCut = "^D")]
13+
public static void DumpData()
14+
{
15+
// We always get the root Application object with a call to ExcelDnaUtil.Application
16+
// If we reference both Window Forms, and the Excel interop assemblies,
17+
// we need to be a bit careful about which 'Application' we mean.
18+
Application app = (Application)ExcelDnaUtil.Application;
19+
var newBook = app.Workbooks.Add();
20+
21+
// While .NET arrays and collections are 0-based,
22+
// COM collections like Workbook.Sheets are 1-based.
23+
// We could also say newBook.Sheets["Sheet1"].
24+
Range targetRange = newBook.Sheets[1].Range["A1:C2"];
25+
26+
// Set values to a range as a 2D object[,] array.
27+
object[,] newValues = new object[,] { { "One", 2, "Three" }, { true, System.DateTime.Now, "" } };
28+
targetRange.Value = newValues;
29+
30+
// Apply some formatting, so that the time is displayed correctly
31+
Range dateCell = targetRange.Cells[2, 2];
32+
dateCell.NumberFormat = "hh:mm:ss";
33+
}
34+
}
35+
}

ExcelDNAVSExtension/CSProjectTemplate/ProjectTemplate.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<ItemGroup>
5151
<Compile Include="Properties\AssemblyInfo.cs" />
5252
<Compile Include="MyFunctions.cs" />
53+
<Compile Include="MyCommands.cs" />
5354
</ItemGroup>
5455
$if$ ($exceldnaincluderibbon$ == true)
5556
<ItemGroup>

ExcelDNAVSExtension/ExcelDNAVSExtension/ExcelDNAVSExtension.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@
8282
</Content>
8383
<Content Include="Resources\VSPackage.ico" />
8484
<None Include="Key.snk" />
85+
<Content Include="Packages\exceldna.interop.14.0.1.nupkg">
86+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
87+
<IncludeInVSIX>true</IncludeInVSIX>
88+
</Content>
8589
<None Include="source.extension.vsixmanifest">
8690
<SubType>Designer</SubType>
8791
</None>
Binary file not shown.

ExcelDNAVSExtension/ExcelDNAVSExtension/source.extension.vsixmanifest

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<Asset Type="Microsoft.VisualStudio.ProjectTemplate" d:Source="Project" d:ProjectName="CSProjectTemplate" d:TargetPath="|CSProjectTemplate;TemplateProjectOutputGroup|" Path="ProjectTemplates" d:VsixSubPath="ProjectTemplates" />
1919
<Asset Type="nupkg" d:Source="File" Path="Packages\exceldna.addin.1.1.1.nupkg" d:VsixSubPath="Packages" />
2020
<Asset Type="nupkg" d:Source="File" Path="Packages\exceldna.integration.1.1.0.nupkg" d:VsixSubPath="Packages" />
21+
<Asset Type="nupkg" d:Source="File" Path="Packages\exceldna.interop.14.0.1.nupkg" d:VsixSubPath="Packages" />
2122
<Asset Type="Microsoft.VisualStudio.ProjectTemplate" d:Source="Project" d:ProjectName="VBProjectTemplate" d:TargetPath="|VBProjectTemplate;TemplateProjectOutputGroup|" Path="ProjectTemplates" d:VsixSubPath="ProjectTemplates" />
2223
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
2324
<Asset Type="Microsoft.VisualStudio.Assembly" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%|" AssemblyName="|%CurrentProject%;AssemblyName|" />

0 commit comments

Comments
 (0)