2023-04-06 08:29:39 +03:00
|
|
|
|
namespace RhSolutions.Services;
|
|
|
|
|
|
2023-04-20 09:37:07 +03:00
|
|
|
|
public class FileDialog : IFileDialog
|
2023-04-06 08:29:39 +03:00
|
|
|
|
{
|
2023-04-20 09:39:25 +03:00
|
|
|
|
private readonly Application _application;
|
2023-04-06 08:29:39 +03:00
|
|
|
|
|
2023-04-20 09:37:07 +03:00
|
|
|
|
public FileDialog(Application application)
|
2023-04-06 08:29:39 +03:00
|
|
|
|
{
|
|
|
|
|
_application = application;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetFile()
|
|
|
|
|
{
|
|
|
|
|
var dialog = _application.FileDialog[Microsoft.Office.Core.MsoFileDialogType.msoFileDialogFilePicker];
|
|
|
|
|
dialog.AllowMultiSelect = false;
|
|
|
|
|
dialog.Filters.Add("Файлы Excel", "*.xls; *.xlsx; *.xlsm");
|
|
|
|
|
|
|
|
|
|
if (dialog.Show() == -1)
|
|
|
|
|
{
|
|
|
|
|
return dialog.SelectedItems.Item(1);
|
|
|
|
|
}
|
|
|
|
|
else return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string[] GetFiles()
|
|
|
|
|
{
|
|
|
|
|
var dialog = _application.FileDialog[Microsoft.Office.Core.MsoFileDialogType.msoFileDialogFilePicker];
|
|
|
|
|
dialog.AllowMultiSelect = true;
|
|
|
|
|
dialog.Filters.Add("Файлы Excel", "*.xls; *.xlsx; *.xlsm");
|
|
|
|
|
|
|
|
|
|
if (dialog.Show() == -1)
|
|
|
|
|
{
|
|
|
|
|
List<string> files = new();
|
|
|
|
|
|
|
|
|
|
foreach (string file in dialog.SelectedItems)
|
|
|
|
|
{
|
|
|
|
|
files.Add(file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return files.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else return Array.Empty<string>();
|
|
|
|
|
}
|
|
|
|
|
}
|