aboutsummaryrefslogtreecommitdiff
path: root/src/Forms/Dialog.cs
blob: cc1c29a94a5c59c0179ca3bfbc618cc4431411c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using Microsoft.Office.Interop.Excel;
using System.Collections.Generic;
using System.Windows.Forms;

namespace RehauSku.Forms
{
    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);
        }
    }
}