diff options
author | Sergey Chebotar <s.chebotar@gmail.com> | 2022-02-02 09:46:47 +0300 |
---|---|---|
committer | Sergey Chebotar <s.chebotar@gmail.com> | 2022-02-02 09:46:47 +0300 |
commit | 06799119fb83cb6b75721c5cf60f4051e50976a7 (patch) | |
tree | bb25db1abb672764f2a25a10e81bcc23579eaea3 /src/Interface/Dialog.cs | |
parent | 7e5020ec253df1d0d32304ba72cdaa62937bb26b (diff) |
Add Interface namespace
Diffstat (limited to 'src/Interface/Dialog.cs')
-rw-r--r-- | src/Interface/Dialog.cs | 62 |
1 files changed, 62 insertions, 0 deletions
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<string> fileNames = new List<string>(); + + 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); + } + } +} |