46 lines
1.2 KiB
C#
46 lines
1.2 KiB
C#
namespace RhSolutions.Services;
|
|
|
|
public class FileDialog : IFileDialog
|
|
{
|
|
private readonly Application _application;
|
|
|
|
public FileDialog(Application application)
|
|
{
|
|
_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>();
|
|
}
|
|
}
|