Compare commits
2 Commits
fd63d004f5
...
7905d3af4d
Author | SHA1 | Date | |
---|---|---|---|
|
7905d3af4d | ||
|
c29849b19d |
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"dotnet.defaultSolution": "ExcelAddIn.sln"
|
||||||
|
}
|
30
Controllers/RibbonController.cs
Normal file
30
Controllers/RibbonController.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using ExcelDna.Integration.CustomUI;
|
||||||
|
using ExcelAddIn.Tools;
|
||||||
|
|
||||||
|
namespace ExcelAddIn.Controllers;
|
||||||
|
|
||||||
|
public class RibbonController : ExcelRibbon
|
||||||
|
{
|
||||||
|
public override string GetCustomUI(string ribbonID)
|
||||||
|
{
|
||||||
|
return @"<customUI xmlns='http://schemas.microsoft.com/office/2006/01/customui'>
|
||||||
|
<ribbon>
|
||||||
|
<tabs>
|
||||||
|
<tab id='MyAddinTab' label='My Addin Tab'>
|
||||||
|
<group id='MyAddinGroup' label='My Addin Group'>
|
||||||
|
<button id='Button1' label='Button 1' size='large' imageMso='HappyFace' onAction='OnToolPressed'/>
|
||||||
|
<button id='Button2' label='Button 2' size='large' imageMso='SadFace' onAction='OnToolPressed'/>
|
||||||
|
<button id='Button3' label='Button 3' size='large' imageMso='Piggy' onAction='OnToolPressed'/>
|
||||||
|
</group>
|
||||||
|
</tab>
|
||||||
|
</tabs>
|
||||||
|
</ribbon>
|
||||||
|
</customUI>";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnToolPressed(IRibbonControl control)
|
||||||
|
{
|
||||||
|
using var tool = ToolFactory.GetTool(control);
|
||||||
|
tool.Execute();
|
||||||
|
}
|
||||||
|
}
|
@ -3,11 +3,13 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0-windows</TargetFramework>
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
<Nullable>disable</Nullable>
|
<Nullable>disable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="ExcelDna.AddIn" Version="1.6.0" />
|
<PackageReference Include="ExcelDna.AddIn" Version="1.6.0" />
|
||||||
|
<PackageReference Include="ExcelDna.Interop" Version="15.0.1" />
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
25
ExcelAddIn.sln
Normal file
25
ExcelAddIn.sln
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.5.001.0
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExcelAddIn", "ExcelAddIn.csproj", "{E352C4DC-88E8-46E3-9CCE-C11702296628}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{E352C4DC-88E8-46E3-9CCE-C11702296628}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{E352C4DC-88E8-46E3-9CCE-C11702296628}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{E352C4DC-88E8-46E3-9CCE-C11702296628}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{E352C4DC-88E8-46E3-9CCE-C11702296628}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {097E31CF-2F26-40D7-AFC3-D5B8DDD45352}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
14
Tools/Button1Tool.cs
Normal file
14
Tools/Button1Tool.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
namespace ExcelAddIn.Tools;
|
||||||
|
|
||||||
|
public class Button1Tool : Tool
|
||||||
|
{
|
||||||
|
public override void Execute()
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Message from {nameof(Button1Tool)}");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
30
Tools/Button2Tool.cs
Normal file
30
Tools/Button2Tool.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using Application = Microsoft.Office.Interop.Excel.Application;
|
||||||
|
|
||||||
|
namespace ExcelAddIn.Tools;
|
||||||
|
|
||||||
|
public class Button2Tool : Tool
|
||||||
|
{
|
||||||
|
private readonly Application app;
|
||||||
|
public Button2Tool()
|
||||||
|
{
|
||||||
|
app = (Application)ExcelDnaUtil.Application;
|
||||||
|
}
|
||||||
|
public override void Execute()
|
||||||
|
{
|
||||||
|
if (app.ActiveCell == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double? cellValue = app.ActiveCell.Cells.Value2;
|
||||||
|
if (cellValue != null)
|
||||||
|
{
|
||||||
|
app.ActiveCell.Cells.Value2 = ++cellValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
24
Tools/Button3Tool.cs
Normal file
24
Tools/Button3Tool.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using Application = Microsoft.Office.Interop.Excel.Application;
|
||||||
|
|
||||||
|
namespace ExcelAddIn.Tools;
|
||||||
|
|
||||||
|
public class Button3Tool : Tool
|
||||||
|
{
|
||||||
|
private readonly Application app;
|
||||||
|
public Button3Tool()
|
||||||
|
{
|
||||||
|
app = (Application)ExcelDnaUtil.Application;
|
||||||
|
}
|
||||||
|
public override void Execute()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 10;)
|
||||||
|
{
|
||||||
|
Thread.Sleep(400);
|
||||||
|
app.StatusBar = $"Выполнено {++i * 10}%...";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
app.StatusBar = false;
|
||||||
|
}
|
||||||
|
}
|
14
Tools/Tool.cs
Normal file
14
Tools/Tool.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
namespace ExcelAddIn.Tools;
|
||||||
|
|
||||||
|
public abstract class Tool : IDisposable
|
||||||
|
{
|
||||||
|
public abstract void Execute();
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void Dispose(bool disposing);
|
||||||
|
}
|
17
Tools/ToolFactory.cs
Normal file
17
Tools/ToolFactory.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using ExcelDna.Integration.CustomUI;
|
||||||
|
|
||||||
|
namespace ExcelAddIn.Tools;
|
||||||
|
|
||||||
|
public static class ToolFactory
|
||||||
|
{
|
||||||
|
public static Tool GetTool(IRibbonControl control)
|
||||||
|
{
|
||||||
|
return control.Id switch
|
||||||
|
{
|
||||||
|
"Button1" => new Button1Tool(),
|
||||||
|
"Button2" => new Button2Tool(),
|
||||||
|
"Button3" => new Button3Tool(),
|
||||||
|
_ => throw new NotImplementedException(control.Id)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user