From 06799119fb83cb6b75721c5cf60f4051e50976a7 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 2 Feb 2022 09:46:47 +0300 Subject: Add Interface namespace --- src/Interface/Dialog.cs | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/Interface/Dialog.cs (limited to 'src/Interface/Dialog.cs') diff --git a/src/Interface/Dialog.cs b/src/Interface/Dialog.cs new file mode 100644 index 0000000..c888703 --- /dev/null +++ b/src/Interface/Dialog.cs @@ -0,0 +1,62 @@ +using Microsoft.Office.Interop.Excel; +using System.Collections.Generic; +using System.Windows.Forms; + +namespace RehauSku.Interface +{ + static class Dialog + { + public static string GetFilePath() + { + string filePath = string.Empty; + + using (OpenFileDialog dialog = new OpenFileDialog()) + { + dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm"; + + if (dialog.ShowDialog() == DialogResult.OK) + { + filePath = dialog.FileName; + } + } + + return filePath; + } + + public static string[] GetMultiplyFiles() + { + List fileNames = new List(); + + using (OpenFileDialog dialog = new OpenFileDialog()) + { + dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm"; + dialog.Multiselect = true; + + if (dialog.ShowDialog() == DialogResult.OK) + { + foreach (string file in dialog.FileNames) + { + fileNames.Add(file); + } + } + } + + return fileNames.ToArray(); + } + + public static void SaveWorkbookAs() + { + Workbook wb = AddIn.Excel.ActiveWorkbook; + string currentFilename = wb.FullName; + string fileFilter = "Файлы Excel (*.xls;*.xlsx;*.xlsm),*.xls;*.xlsx;*.xlsm"; + + object fileName = AddIn.Excel.GetSaveAsFilename(currentFilename, fileFilter); + + if (fileName.GetType() == typeof(string)) + wb.SaveAs(fileName); + + else + wb.Close(false); + } + } +} -- cgit v1.2.3 From 7f3487d9132bf9b9e83a202c0ce04230926d56fd Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 2 Feb 2022 17:58:54 +0300 Subject: Change Excel SaveAs to Windows Forms SaveFileDialog --- src/Interface/Dialog.cs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/Interface/Dialog.cs') diff --git a/src/Interface/Dialog.cs b/src/Interface/Dialog.cs index c888703..6b05dc8 100644 --- a/src/Interface/Dialog.cs +++ b/src/Interface/Dialog.cs @@ -46,17 +46,22 @@ namespace RehauSku.Interface public static void SaveWorkbookAs() { - Workbook wb = AddIn.Excel.ActiveWorkbook; - string currentFilename = wb.FullName; - string fileFilter = "Файлы Excel (*.xls;*.xlsx;*.xlsm),*.xls;*.xlsx;*.xlsm"; + Workbook workbook = AddIn.Excel.ActiveWorkbook; - object fileName = AddIn.Excel.GetSaveAsFilename(currentFilename, fileFilter); + using (SaveFileDialog dialog = new SaveFileDialog()) + { + dialog.FileName = workbook.Name; + dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm"; + + if (dialog.ShowDialog() == DialogResult.Cancel) + { + workbook.Close(false); + } - if (fileName.GetType() == typeof(string)) - wb.SaveAs(fileName); + string fileName = dialog.FileName; - else - wb.Close(false); + workbook.SaveAs(fileName); + } } } } -- cgit v1.2.3 From 94b7c4a52bc97026a9b24b7d703174f21f315912 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 2 Feb 2022 18:13:03 +0300 Subject: SaveWorkbookAs edit --- src/Interface/Dialog.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/Interface/Dialog.cs') diff --git a/src/Interface/Dialog.cs b/src/Interface/Dialog.cs index 6b05dc8..f8ab645 100644 --- a/src/Interface/Dialog.cs +++ b/src/Interface/Dialog.cs @@ -58,9 +58,11 @@ namespace RehauSku.Interface workbook.Close(false); } - string fileName = dialog.FileName; - - workbook.SaveAs(fileName); + else + { + string fileName = dialog.FileName; + workbook.SaveAs(fileName); + } } } } -- cgit v1.2.3 From 9018d7d504dfebbec9a3c75851314d25d1e8197c Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 2 Feb 2022 18:26:04 +0300 Subject: Edit Open File Dialogs --- src/Interface/Dialog.cs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'src/Interface/Dialog.cs') diff --git a/src/Interface/Dialog.cs b/src/Interface/Dialog.cs index f8ab645..806e92d 100644 --- a/src/Interface/Dialog.cs +++ b/src/Interface/Dialog.cs @@ -8,25 +8,21 @@ namespace RehauSku.Interface { public static string GetFilePath() { - string filePath = string.Empty; - using (OpenFileDialog dialog = new OpenFileDialog()) { dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm"; if (dialog.ShowDialog() == DialogResult.OK) { - filePath = dialog.FileName; + return dialog.FileName; } } - return filePath; + return string.Empty; } public static string[] GetMultiplyFiles() { - List fileNames = new List(); - using (OpenFileDialog dialog = new OpenFileDialog()) { dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm"; @@ -34,14 +30,11 @@ namespace RehauSku.Interface if (dialog.ShowDialog() == DialogResult.OK) { - foreach (string file in dialog.FileNames) - { - fileNames.Add(file); - } + return dialog.FileNames; } - } - return fileNames.ToArray(); + else return null; + } } public static void SaveWorkbookAs() -- cgit v1.2.3 From 5001219695090d4a6ead73b2d17434b0805516a3 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 2 Feb 2022 18:34:32 +0300 Subject: Do not delete template path on registry key if cancel pick template dialog --- src/Interface/Dialog.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Interface/Dialog.cs') diff --git a/src/Interface/Dialog.cs b/src/Interface/Dialog.cs index 806e92d..23f65d7 100644 --- a/src/Interface/Dialog.cs +++ b/src/Interface/Dialog.cs @@ -16,9 +16,9 @@ namespace RehauSku.Interface { return dialog.FileName; } - } - return string.Empty; + else return string.Empty; + } } public static string[] GetMultiplyFiles() -- cgit v1.2.3