diff options
author | Serghei Cebotari <51533848+schebotar@users.noreply.github.com> | 2022-02-05 13:18:18 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-05 13:18:18 +0300 |
commit | ad7234fda7927c45e5ca457facae71a4b9be6b31 (patch) | |
tree | d9fc89b0e02a5fdc92d54674b7b48ad2d10859e4 /src/Interface/Dialog.cs | |
parent | 180807d749f4eb3a16c1f136d42b90ea2945008f (diff) | |
parent | eb6a28b955b5b179bd40f21dcf1daa6f9337765f (diff) |
Merge pull request #15 from schebotar/dev
Dev
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..23f65d7 --- /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() + { + using (OpenFileDialog dialog = new OpenFileDialog()) + { + dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm"; + + if (dialog.ShowDialog() == DialogResult.OK) + { + return dialog.FileName; + } + + else return string.Empty; + } + } + + public static string[] GetMultiplyFiles() + { + using (OpenFileDialog dialog = new OpenFileDialog()) + { + dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm"; + dialog.Multiselect = true; + + if (dialog.ShowDialog() == DialogResult.OK) + { + return dialog.FileNames; + } + + else return null; + } + } + + public static void SaveWorkbookAs() + { + Workbook workbook = AddIn.Excel.ActiveWorkbook; + + 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); + } + + else + { + string fileName = dialog.FileName; + workbook.SaveAs(fileName); + } + } + } + } +} |