From 7f3487d9132bf9b9e83a202c0ce04230926d56fd Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 2 Feb 2022 17:58:54 +0300 Subject: [PATCH] Change Excel SaveAs to Windows Forms SaveFileDialog --- src/Interface/Dialog.cs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) 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 (fileName.GetType() == typeof(string)) - wb.SaveAs(fileName); + if (dialog.ShowDialog() == DialogResult.Cancel) + { + workbook.Close(false); + } - else - wb.Close(false); + string fileName = dialog.FileName; + + workbook.SaveAs(fileName); + } } } }