From 70ec02bfbd7a9496a2600e5c621c8382145cec67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 1 Oct 2024 11:20:00 +0400 Subject: [PATCH] =?UTF-8?q?2=20=D0=BB=D0=B0=D0=B1=D0=B0=20=D0=B3=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=D0=B0=20=D0=BF=D0=BE=D0=BB=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- COP/Components/LogicalComponents/ExcelImagesComponent.cs | 4 ++++ COP/WinFormsTest/FormTest.Designer.cs | 1 + COP/WinFormsTest/FormTest.cs | 8 +++++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/COP/Components/LogicalComponents/ExcelImagesComponent.cs b/COP/Components/LogicalComponents/ExcelImagesComponent.cs index d791726..d99cbb3 100644 --- a/COP/Components/LogicalComponents/ExcelImagesComponent.cs +++ b/COP/Components/LogicalComponents/ExcelImagesComponent.cs @@ -25,6 +25,10 @@ namespace Components.LogicalComponents } public bool createWithImages(ExcelImageInfo info) { + if (string.IsNullOrEmpty(info.path) || string.IsNullOrEmpty(info.title) || info.imagePaths == null || info.imagePaths.Length == 0) + { + throw new ArgumentException("Не все поля заполнены."); + } var excelApp = new Microsoft.Office.Interop.Excel.Application { SheetsInNewWorkbook = 1 }; Workbook workbook = excelApp.Workbooks.Add(Type.Missing); try diff --git a/COP/WinFormsTest/FormTest.Designer.cs b/COP/WinFormsTest/FormTest.Designer.cs index d350632..0677660 100644 --- a/COP/WinFormsTest/FormTest.Designer.cs +++ b/COP/WinFormsTest/FormTest.Designer.cs @@ -223,6 +223,7 @@ // openFileDialog // this.openFileDialog.FileName = "openFileDialog"; + this.openFileDialog.Multiselect = true; // // FormTest // diff --git a/COP/WinFormsTest/FormTest.cs b/COP/WinFormsTest/FormTest.cs index 6c36304..cfb7286 100644 --- a/COP/WinFormsTest/FormTest.cs +++ b/COP/WinFormsTest/FormTest.cs @@ -1,5 +1,7 @@ using Components.Exceptions; using Components.LogicalComponents; +using Microsoft.Office.Core; +using Microsoft.VisualBasic.ApplicationServices; using System; using System.Collections.Generic; using System.ComponentModel; @@ -142,7 +144,7 @@ namespace WinFormsTest var files = openFileDialog.FileNames; openFileDialog.Dispose(); List images = new List(); - string path = AppDomain.CurrentDomain.BaseDirectory + "test.xlsx"; + string path = "C:\\Users\\Полина\\source\\repos\\COP\\COP\\WinFormsTest\\test.xlsx"; if (excelImagesComponent.createWithImages(new ExcelImageInfo(path, "Header", files))) MessageBox.Show("Успех!"); else MessageBox.Show("Ошибка, проверьте консоль"); } @@ -154,7 +156,7 @@ namespace WinFormsTest workers.Add(new OfficeWorker(1, "Иванов", "Иван", 20, "Отдел продаж", "Бухгалтер", 25, "+7(834)234-03-49")); workers.Add(new OfficeWorker(1, "Петров", "Петр", 25, "Отдел продаж", "Менеджер", 20, "+7(834)123-03-49")); workers.Add(new OfficeWorker(1, "Сидоров", "Сергей", 27, "Отдел кадров", "HR", 2, "+7(834)593-03-49", true)); - string path = AppDomain.CurrentDomain.BaseDirectory + "test2.xlsx"; + string path = "C:\\Users\\Полина\\source\\repos\\COP\\COP\\WinFormsTest\\test2.xlsx"; List<(int, int)> merges = new List<(int, int)>(); merges.Add((1, 3)); merges.Add((4, 6)); @@ -177,7 +179,7 @@ namespace WinFormsTest departments.Add(new Department("Dep 1", 330)); departments.Add(new Department("Dep 2", 500)); departments.Add(new Department("Dep 3", 170)); - string path = AppDomain.CurrentDomain.BaseDirectory + "test3.xlsx"; + string path = "C:\\Users\\Полина\\source\\repos\\COP\\COP\\WinFormsTest\\test3.xlsx"; if (excelDiagramComponent.createWithDiagram(path, "test3", "Продажи", DiagramLegendEnum.TopRight, departments, "name", "sells")) MessageBox.Show("Успех"); else MessageBox.Show("Fail :("); }