From 543925e6fec55973b8b19b7ab299aca3a831795a Mon Sep 17 00:00:00 2001 From: abazov73 <92822431+abazov73@users.noreply.github.com> Date: Thu, 19 Oct 2023 22:11:11 +0400 Subject: [PATCH] Removed excel image info class --- AbazovApp/AbazovAppView/FormTest.cs | 2 +- .../LogicalComponents/ExcelImageInfo.cs | 22 ------------------- .../LogicalComponents/ExcelImagesComponent.cs | 8 +++---- 3 files changed, 5 insertions(+), 27 deletions(-) delete mode 100644 AbazovApp/AbazovViewComponents/LogicalComponents/ExcelImageInfo.cs diff --git a/AbazovApp/AbazovAppView/FormTest.cs b/AbazovApp/AbazovAppView/FormTest.cs index 6a052d0..bfa9301 100644 --- a/AbazovApp/AbazovAppView/FormTest.cs +++ b/AbazovApp/AbazovAppView/FormTest.cs @@ -138,7 +138,7 @@ namespace AbazovAppView openFileDialog.Dispose(); List images = new List(); string path = AppDomain.CurrentDomain.BaseDirectory + "test.xlsx"; - if (excelImagesComponent.createWithImages(new ExcelImageInfo(path, "Header", files))) MessageBox.Show("Успех!"); + if (excelImagesComponent.createWithImages(path, "Header", files)) MessageBox.Show("Успех!"); else MessageBox.Show("Ошибка, проверьте консоль"); } diff --git a/AbazovApp/AbazovViewComponents/LogicalComponents/ExcelImageInfo.cs b/AbazovApp/AbazovViewComponents/LogicalComponents/ExcelImageInfo.cs deleted file mode 100644 index 179b035..0000000 --- a/AbazovApp/AbazovViewComponents/LogicalComponents/ExcelImageInfo.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AbazovViewComponents.LogicalComponents -{ - public class ExcelImageInfo - { - public ExcelImageInfo(string path, string title, string[] imagePaths) - { - this.path = path; - this.title = title; - this.imagePaths = imagePaths; - } - - public string path; - public string title; - public string[] imagePaths; - } -} diff --git a/AbazovApp/AbazovViewComponents/LogicalComponents/ExcelImagesComponent.cs b/AbazovApp/AbazovViewComponents/LogicalComponents/ExcelImagesComponent.cs index 26cfe6d..94f3aa3 100644 --- a/AbazovApp/AbazovViewComponents/LogicalComponents/ExcelImagesComponent.cs +++ b/AbazovApp/AbazovViewComponents/LogicalComponents/ExcelImagesComponent.cs @@ -24,7 +24,7 @@ namespace AbazovViewComponents.LogicalComponents InitializeComponent(); } - public bool createWithImages(ExcelImageInfo info) + public bool createWithImages(string pathToFile, string title, string[] imagePaths) { var excelApp = new Microsoft.Office.Interop.Excel.Application { SheetsInNewWorkbook = 1 }; Workbook workbook = excelApp.Workbooks.Add(Type.Missing); @@ -43,10 +43,10 @@ namespace AbazovViewComponents.LogicalComponents excelcells.RowHeight = 25; excelcells.HorizontalAlignment = Constants.xlCenter; excelcells.VerticalAlignment = Constants.xlCenter; - excelcells.Value2 = info.title; + excelcells.Value2 = title; int topOffset = 25; - foreach (string path in info.imagePaths) + foreach (string path in imagePaths) { Bitmap bm = new Bitmap(path); worksheet.Shapes.AddPicture2(path, MsoTriState.msoFalse, MsoTriState.msoCTrue, 0, topOffset, bm.Width, bm.Height, MsoPictureCompress.msoPictureCompressFalse); @@ -56,7 +56,7 @@ namespace AbazovViewComponents.LogicalComponents //save object missing = System.Reflection.Missing.Value; - workbook.SaveAs(info.path, XlFileFormat.xlOpenXMLWorkbook, missing, missing, false, false, XlSaveAsAccessMode.xlNoChange, + workbook.SaveAs(pathToFile, XlFileFormat.xlOpenXMLWorkbook, missing, missing, false, false, XlSaveAsAccessMode.xlNoChange, XlSaveConflictResolution.xlUserResolution, true, missing, missing, missing); workbook.Close(); excelApp.Quit();