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