Compare commits
No commits in common. "7905d3af4d32405ef041de897bf2d23ee7d6d08e" and "fd63d004f5f1d74e01f60bfec4fc80fbd6b14e74" have entirely different histories.
7905d3af4d
...
fd63d004f5
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -1,3 +0,0 @@
|
||||
{
|
||||
"dotnet.defaultSolution": "ExcelAddIn.sln"
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
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,13 +3,11 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<Nullable>disable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<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.Http" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
@ -1,25 +0,0 @@
|
||||
|
||||
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
|
@ -1,14 +0,0 @@
|
||||
namespace ExcelAddIn.Tools;
|
||||
|
||||
public class Button1Tool : Tool
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
MessageBox.Show($"Message from {nameof(Button1Tool)}");
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
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);
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
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