Removed excel image info class

This commit is contained in:
abazov73 2023-10-19 22:11:11 +04:00
parent d302d4644b
commit 543925e6fe
3 changed files with 5 additions and 27 deletions

View File

@ -138,7 +138,7 @@ namespace AbazovAppView
openFileDialog.Dispose();
List<Bitmap> images = new List<Bitmap>();
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("Ошибка, проверьте консоль");
}

View File

@ -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;
}
}

View File

@ -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();