RhSolutions-AddIn/RhSolutions.AddIn/Services/ExcelFileDialog.cs

46 lines
1.2 KiB
C#
Raw Normal View History

2023-04-06 08:29:39 +03:00
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>();
}
}