summaryrefslogtreecommitdiff
path: root/Tools
diff options
context:
space:
mode:
authorSergey Chebotar <s.chebotar@gmail.com>2023-06-14 15:23:33 +0300
committerSergey Chebotar <s.chebotar@gmail.com>2023-06-14 15:23:33 +0300
commit7905d3af4d32405ef041de897bf2d23ee7d6d08e (patch)
treea51153a14fc394e1c37a3cc7839cf57ac692bb68 /Tools
parentc29849b19d444956f002a65377610f639c0873e1 (diff)
Add custom panel and tools
Diffstat (limited to 'Tools')
-rw-r--r--Tools/Button1Tool.cs14
-rw-r--r--Tools/Button2Tool.cs30
-rw-r--r--Tools/Button3Tool.cs24
-rw-r--r--Tools/Tool.cs14
-rw-r--r--Tools/ToolFactory.cs17
5 files changed, 99 insertions, 0 deletions
diff --git a/Tools/Button1Tool.cs b/Tools/Button1Tool.cs
new file mode 100644
index 0000000..5468398
--- /dev/null
+++ b/Tools/Button1Tool.cs
@@ -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)
+ {
+
+ }
+}
diff --git a/Tools/Button2Tool.cs b/Tools/Button2Tool.cs
new file mode 100644
index 0000000..db7afc3
--- /dev/null
+++ b/Tools/Button2Tool.cs
@@ -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)
+ {
+
+ }
+} \ No newline at end of file
diff --git a/Tools/Button3Tool.cs b/Tools/Button3Tool.cs
new file mode 100644
index 0000000..853ed95
--- /dev/null
+++ b/Tools/Button3Tool.cs
@@ -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;
+ }
+} \ No newline at end of file
diff --git a/Tools/Tool.cs b/Tools/Tool.cs
new file mode 100644
index 0000000..08ab910
--- /dev/null
+++ b/Tools/Tool.cs
@@ -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);
+}
diff --git a/Tools/ToolFactory.cs b/Tools/ToolFactory.cs
new file mode 100644
index 0000000..dba781e
--- /dev/null
+++ b/Tools/ToolFactory.cs
@@ -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)
+ };
+ }
+}