2022-01-09 15:47:54 +03:00
|
|
|
|
using Microsoft.Office.Interop.Excel;
|
|
|
|
|
using System.Collections.Generic;
|
2021-12-24 16:22:03 +03:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace RehauSku.Forms
|
|
|
|
|
{
|
|
|
|
|
static class Dialog
|
|
|
|
|
{
|
|
|
|
|
public static string GetFilePath()
|
|
|
|
|
{
|
|
|
|
|
string filePath = string.Empty;
|
|
|
|
|
|
|
|
|
|
using (OpenFileDialog dialog = new OpenFileDialog())
|
|
|
|
|
{
|
2021-12-24 17:42:20 +03:00
|
|
|
|
dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm";
|
2021-12-24 16:22:03 +03:00
|
|
|
|
|
|
|
|
|
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())
|
|
|
|
|
{
|
2021-12-24 17:42:20 +03:00
|
|
|
|
dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm";
|
2021-12-24 16:22:03 +03:00
|
|
|
|
dialog.Multiselect = true;
|
|
|
|
|
|
|
|
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
foreach (string file in dialog.FileNames)
|
|
|
|
|
{
|
|
|
|
|
fileNames.Add(file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fileNames.ToArray();
|
|
|
|
|
}
|
2022-01-09 15:47:54 +03:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
2021-12-24 16:22:03 +03:00
|
|
|
|
}
|
|
|
|
|
}
|