2 компонент 2 лаба
This commit is contained in:
parent
d1c4275408
commit
1e39b833c9
@ -1,9 +1,15 @@
|
|||||||
using COP.Info;
|
using COP.Info;
|
||||||
|
using DocumentFormat.OpenXml.EMMA;
|
||||||
|
using DocumentFormat.OpenXml.Office2010.Excel;
|
||||||
|
using DocumentFormat.OpenXml.Spreadsheet;
|
||||||
using NPOI.HSSF.Util;
|
using NPOI.HSSF.Util;
|
||||||
using NPOI.SS.UserModel;
|
using NPOI.SS.UserModel;
|
||||||
|
using NPOI.SS.Util;
|
||||||
using NPOI.XSSF.UserModel;
|
using NPOI.XSSF.UserModel;
|
||||||
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using BorderStyle = NPOI.SS.UserModel.BorderStyle;
|
using BorderStyle = NPOI.SS.UserModel.BorderStyle;
|
||||||
|
using HorizontalAlignment = NPOI.SS.UserModel.HorizontalAlignment;
|
||||||
|
|
||||||
namespace COP
|
namespace COP
|
||||||
{
|
{
|
||||||
@ -21,7 +27,7 @@ namespace COP
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GenerateDocument(ExcelTableInfo info)
|
public void GenerateDocument<T>(ExcelTableInfo<T> info) where T: class
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(info.FilePath))
|
if (string.IsNullOrEmpty(info.FilePath))
|
||||||
{
|
{
|
||||||
@ -36,154 +42,102 @@ namespace COP
|
|||||||
throw new ArgumentException("Data is null or empty.");
|
throw new ArgumentException("Data is null or empty.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Создание документа и листа
|
|
||||||
var workbook = new XSSFWorkbook();
|
var workbook = new XSSFWorkbook();
|
||||||
var sheet = workbook.CreateSheet("Sheet1");
|
var sheet = workbook.CreateSheet("Sheet1");
|
||||||
|
|
||||||
// Установка заголовка документа в первой строке листа
|
|
||||||
sheet.CreateRow(0).CreateCell(0).SetCellValue(info.DocumentTitle);
|
sheet.CreateRow(0).CreateCell(0).SetCellValue(info.DocumentTitle);
|
||||||
|
|
||||||
int posString = 2;
|
int curRow = 1;
|
||||||
int posColumn = 1;
|
int curCol = 0;
|
||||||
List<string> properties = new();
|
List<string> headers = new();
|
||||||
|
|
||||||
foreach (var property in info.Properties)
|
var dataCellStyle = GetDataCellStyle(workbook);
|
||||||
|
var headerCellStyle = GetHeaderCellStyle(workbook);
|
||||||
|
|
||||||
|
foreach (var header in info.Headers)
|
||||||
{
|
{
|
||||||
if (property.Value.Item1.Count == 1)
|
headers.Add(header.Key);
|
||||||
|
|
||||||
|
var currentRow = sheet.CreateRow(curRow);
|
||||||
|
var curCell = currentRow.CreateCell(curCol);
|
||||||
|
|
||||||
|
if (header.Value.Item1.Item1.Count > 1)
|
||||||
{
|
{
|
||||||
var cell1 = sheet.GetRow(posString).CreateCell(posColumn);
|
sheet.AddMergedRegion(new CellRangeAddress(curRow, curRow + header.Value.Item1.Item1.Count - 1, curCol, curCol));
|
||||||
cell1.SetCellValue(property.Key);
|
curCol++;
|
||||||
cell1.CellStyle.FillPattern = FillPattern.SolidForeground;
|
foreach (var item in header.Value.Item1.Item2)
|
||||||
cell1.CellStyle.FillForegroundColor = HSSFColor.LightGreen.Index;
|
{
|
||||||
properties.Add(property.Key);
|
int id = header.Value.Item1.Item2.IndexOf(item);
|
||||||
posString++;
|
var cellValue = currentRow.CreateCell(1);
|
||||||
continue;
|
cellValue.SetCellValue(item);
|
||||||
|
currentRow.Height = (short)(header.Value.Item2[id] * 20);
|
||||||
|
headers.Add(item);
|
||||||
|
cellValue.CellStyle = headerCellStyle;
|
||||||
|
currentRow = sheet.CreateRow(currentRow.RowNum + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int id = header.Value.Item1.Item1.IndexOf(header.Value.Item1.Item1.First());
|
||||||
|
sheet.AddMergedRegion(new CellRangeAddress(curRow, curRow, curCol, curCol + 1));
|
||||||
|
currentRow.Height = (short)(header.Value.Item2[id] * 20);
|
||||||
|
curRow++;
|
||||||
}
|
}
|
||||||
|
|
||||||
var cell = sheet.GetRow(posString).CreateCell(posColumn);
|
curCell.SetCellValue(header.Key);
|
||||||
cell.SetCellValue(property.Key);
|
curCell.CellStyle = headerCellStyle;
|
||||||
cell.CellStyle.Rotation = 180;
|
if (header.Value.Item1.Item1.Count > 1)
|
||||||
cell.CellStyle.FillPattern = FillPattern.SolidForeground;
|
|
||||||
cell.CellStyle.FillForegroundColor = HSSFColor.Aqua.Index;
|
|
||||||
sheet.SetColumnWidth(posColumn, sheet.DefaultColumnWidth);
|
|
||||||
|
|
||||||
posColumn++;
|
|
||||||
|
|
||||||
foreach (var field in property.Value.Item1)
|
|
||||||
{
|
{
|
||||||
int id = property.Value.Item1.IndexOf(field);
|
curCol--;
|
||||||
var cellValue = sheet.GetRow(posString).CreateCell(posColumn);
|
curRow += header.Value.Item1.Item1.Count;
|
||||||
cellValue.SetCellValue(field);
|
|
||||||
cellValue.CellStyle.FillPattern = FillPattern.SolidForeground;
|
|
||||||
cellValue.CellStyle.FillForegroundColor = HSSFColor.Aqua.Index;
|
|
||||||
sheet.GetRow(posString).Height = (short)property.Value.Item2[id];
|
|
||||||
properties.Add(field);
|
|
||||||
posString++;
|
|
||||||
}
|
}
|
||||||
posColumn--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
posColumn = 3;
|
curCol = 2;
|
||||||
|
|
||||||
foreach (var data in info.Data)
|
foreach (var data in info.Data)
|
||||||
{
|
{
|
||||||
posString = 2;
|
curRow = 1;
|
||||||
|
|
||||||
var type = data.GetType();
|
foreach (var header in info.Headers.Values)
|
||||||
|
|
||||||
foreach (var property in properties)
|
|
||||||
{
|
{
|
||||||
var cellValue = sheet.GetRow(posString).CreateCell(posColumn);
|
foreach (var item in header.Item1.Item1)
|
||||||
cellValue.SetCellValue((string)(type.GetField(property) == null ? type.GetProperty(property).GetValue(data) : type.GetField(property).GetValue(data)));
|
|
||||||
posString++;
|
|
||||||
}
|
|
||||||
posColumn++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*var dataCellStyle = GetDataCellStyle(workbook);
|
|
||||||
|
|
||||||
for (int row = 0; row < info.HeaderTitles.Count; row++)
|
|
||||||
{
|
|
||||||
// Создание заголовков для шапки таблицы
|
|
||||||
var headerRow = sheet.CreateRow(row + 1);
|
|
||||||
var headerCellStyle = GetHeaderCellStyle(workbook);
|
|
||||||
var cell = headerRow.CreateCell(0);
|
|
||||||
cell.SetCellValue(info.HeaderTitles[row]);
|
|
||||||
cell.CellStyle = headerCellStyle;
|
|
||||||
// Заполнение таблицы
|
|
||||||
for (int col = 0; col < info.Data.Count; col++)
|
|
||||||
{
|
|
||||||
var dataCell = headerRow.CreateCell(col + 2);
|
|
||||||
var value = GetPropertyValue(info.Data[col], row);
|
|
||||||
dataCell.SetCellValue(value.ToString());
|
|
||||||
dataCell.CellStyle = dataCellStyle;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// Объединение ячеек в шапке таблицы
|
|
||||||
/*for (int i = 0; i < info.MergeInfo.Count; i++)
|
|
||||||
{
|
|
||||||
var cellMergeInfo = info.MergeInfo[i];
|
|
||||||
var mergeStartCellRef = CellReference.ConvertNumToColString(cellMergeInfo.StartCol) + (cellMergeInfo.StartRow + 1);
|
|
||||||
var mergeEndCellRef = CellReference.ConvertNumToColString(cellMergeInfo.EndCol) + (cellMergeInfo.EndRow + 1);
|
|
||||||
|
|
||||||
sheet.AddMergedRegion(new CellRangeAddress(cellMergeInfo.StartRow, cellMergeInfo.EndRow, cellMergeInfo.StartCol, cellMergeInfo.EndCol));
|
|
||||||
|
|
||||||
var mergeCell = sheet.GetRow(cellMergeInfo.StartRow).CreateCell(cellMergeInfo.StartCol);
|
|
||||||
mergeCell.SetCellValue(cellMergeInfo.Value);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*for (int row = 0; row < info.HeaderTitles.Count; row++)
|
|
||||||
{
|
|
||||||
sheet.AddMergedRegion(new CellRangeAddress(row, row, 0, 1));
|
|
||||||
foreach (var merge in info.MergeInfo)
|
|
||||||
if (merge.Value != "")
|
|
||||||
{
|
{
|
||||||
sheet.RemoveMergedRegion(row)
|
var property = typeof(T).GetProperty(item);
|
||||||
}
|
var cellValue = sheet.GetRow(curRow)?.CreateCell(curCol);
|
||||||
foreach (var mergedRegion in mergedRegions)
|
if (cellValue != null && property != null)
|
||||||
{
|
{
|
||||||
sheet.RemoveMergedRegion(mergedRegion);
|
var value = property?.GetValue(data)?.ToString();
|
||||||
|
var rowHeight = GetRowHeight(item, info);
|
||||||
|
var currentRow = sheet.GetRow(curRow);
|
||||||
|
if (rowHeight != null)
|
||||||
|
{
|
||||||
|
currentRow.Height = (short)(rowHeight.Value * 20);
|
||||||
|
}
|
||||||
|
cellValue.SetCellValue(value);
|
||||||
|
cellValue.CellStyle = dataCellStyle;
|
||||||
|
}
|
||||||
|
curRow++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}*/
|
curCol++;
|
||||||
|
}
|
||||||
/*foreach (var merge in info.MergeInfo)
|
|
||||||
{
|
|
||||||
for (int row = 0; row < info.HeaderTitles.Count; row++)
|
|
||||||
{
|
|
||||||
if (merge.Value != "")
|
|
||||||
{
|
|
||||||
var valueCell = sheet.GetRow(row + 1).GetCell(0);
|
|
||||||
valueCell.SetCellValue(merge.Value);
|
|
||||||
sheet.AddMergedRegion(new CellRangeAddress(merge.StartRow, merge.EndRow, merge.StartCol, merge.EndCol));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sheet.AddMergedRegion(new CellRangeAddress(merge.StartRow, merge.EndRow, 0, 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*// Задание высоты строк
|
|
||||||
for (int i = 0; i < info.MergeInfo.Count; i++)
|
|
||||||
{
|
|
||||||
var row = sheet.GetRow(i);
|
|
||||||
if (row != null)
|
|
||||||
{
|
|
||||||
row.Height = (short)(info.MergeInfo[i].RowHeight * 20);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
using var fs = new FileStream(info.FilePath, FileMode.Create, FileAccess.Write);
|
using var fs = new FileStream(info.FilePath, FileMode.Create, FileAccess.Write);
|
||||||
workbook.Write(fs);
|
workbook.Write(fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static object GetPropertyValue(object obj, int columnIndex)
|
private static int? GetRowHeight<T>(string header, ExcelTableInfo<T> info) where T:class
|
||||||
{
|
{
|
||||||
var properties = obj.GetType().GetProperties();
|
foreach (var item in info.Headers)
|
||||||
var field = properties[columnIndex];
|
{
|
||||||
|
foreach (var elem in item.Value.Item1.Item1)
|
||||||
return field.GetValue(obj);
|
{
|
||||||
|
int id = item.Value.Item1.Item1.IndexOf(elem);
|
||||||
|
if (item.Value.Item1.Item1[id] == header)
|
||||||
|
return item.Value.Item2[id];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ICellStyle GetHeaderCellStyle(IWorkbook workbook)
|
private static ICellStyle GetHeaderCellStyle(IWorkbook workbook)
|
||||||
@ -197,6 +151,8 @@ namespace COP
|
|||||||
var font = workbook.CreateFont();
|
var font = workbook.CreateFont();
|
||||||
font.Boldweight = (short)FontBoldWeight.Bold;
|
font.Boldweight = (short)FontBoldWeight.Bold;
|
||||||
style.SetFont(font);
|
style.SetFont(font);
|
||||||
|
style.Alignment = HorizontalAlignment.Center;
|
||||||
|
style.VerticalAlignment = VerticalAlignment.Center;
|
||||||
|
|
||||||
return style;
|
return style;
|
||||||
}
|
}
|
||||||
@ -212,4 +168,8 @@ namespace COP
|
|||||||
return style;
|
return style;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public class Property
|
||||||
|
{
|
||||||
|
public string? Name { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,77 +1,18 @@
|
|||||||
namespace COP.Info
|
namespace COP.Info
|
||||||
{
|
{
|
||||||
public class ExcelTableInfo
|
public class ExcelTableInfo<T> where T: class
|
||||||
{
|
{
|
||||||
public string? FilePath { get; set; } = string.Empty;
|
public string FilePath { get; set; } = string.Empty;
|
||||||
public string? DocumentTitle { get; set; } = string.Empty;
|
|
||||||
public List<object>? Data { get; set; } = new();
|
|
||||||
public Dictionary<string, (List<string>, List<int>)> Properties = new();
|
|
||||||
|
|
||||||
public ExcelTableInfo(string filePath, string documentTitle, List<object> data, Dictionary<string, (List<string>, List<int>)>? properties)
|
|
||||||
{
|
|
||||||
FilePath = filePath;
|
|
||||||
DocumentTitle = documentTitle;
|
|
||||||
Data = data;
|
|
||||||
Properties = properties;
|
|
||||||
}
|
|
||||||
public void addDictionary(string name, string property, int height)
|
|
||||||
{
|
|
||||||
if (Properties.ContainsKey(name))
|
|
||||||
{
|
|
||||||
Properties[name].Item1.Add(property);
|
|
||||||
Properties[name].Item2.Add(height);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Properties.Add(name, (new List<string>(), new List<int>()));
|
|
||||||
Properties[name].Item1.Add(property);
|
|
||||||
Properties[name].Item2.Add(height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void addDictionaryAlone(string item, int height)
|
|
||||||
{
|
|
||||||
|
|
||||||
Properties.Add(item, (new List<string>(), new List<int>()));
|
|
||||||
Properties[item].Item1.Add(item);
|
|
||||||
Properties[item].Item2.Add(height);
|
|
||||||
|
|
||||||
}
|
|
||||||
/*public string FilePath { get; set; } = string.Empty;
|
|
||||||
public string DocumentTitle { get; set; } = string.Empty;
|
public string DocumentTitle { get; set; } = string.Empty;
|
||||||
public List<MergeInfo> MergeInfo;
|
public List<T>? Data;
|
||||||
public List<string>? HeaderTitles;
|
public Dictionary<string, ((List<string>, List<string>), List<int>)> Headers { get; set; }
|
||||||
public List<object>? Data;
|
|
||||||
public Dictionary<string, (List<string>, List<int>)> Headers { get; set; }
|
|
||||||
public void addDictionary(string name, string header, int height)
|
|
||||||
{
|
|
||||||
if (headers.ContainsKey(name))
|
|
||||||
{
|
|
||||||
headers[name].Item1.Add(header);
|
|
||||||
headers[name].Item2.Add(height);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
headers.Add(name, (new List<string>(), new List<int>()));
|
|
||||||
headers[name].Item1.Add(header);
|
|
||||||
headers[name].Item2.Add(height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void addDictionaryAlone(string header, int height)
|
|
||||||
{
|
|
||||||
|
|
||||||
headers.Add(header, (new List<string>(), new List<int>()));
|
public ExcelTableInfo (string filePath, string documentTitle, List<T> data, Dictionary<string, ((List<string>, List<string>), List<int>)> headers)
|
||||||
headers[header].Item1.Add(header);
|
|
||||||
headers[header].Item2.Add(height);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public ExcelTableInfo(string filePath, string documentTitle, List<MergeInfo> mergeInfo, List<string> headerTitles, List<object> data)
|
|
||||||
{
|
{
|
||||||
FilePath = filePath;
|
FilePath = filePath;
|
||||||
DocumentTitle = documentTitle;
|
DocumentTitle = documentTitle;
|
||||||
MergeInfo = mergeInfo;
|
|
||||||
HeaderTitles = headerTitles;
|
|
||||||
Data = data;
|
Data = data;
|
||||||
}*/
|
Headers = headers;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ namespace COP
|
|||||||
ExcelPieChart? pieChart = worksheet.Drawings.AddChart(info.chartTitle, eChartType.Pie) as ExcelPieChart;
|
ExcelPieChart? pieChart = worksheet.Drawings.AddChart(info.chartTitle, eChartType.Pie) as ExcelPieChart;
|
||||||
pieChart.Title.Text = info.chartTitle;
|
pieChart.Title.Text = info.chartTitle;
|
||||||
pieChart.Series.Add(ExcelCellBase.GetAddress(row + 1, startCol, row + 1, endCol - 1),
|
pieChart.Series.Add(ExcelCellBase.GetAddress(row + 1, startCol, row + 1, endCol - 1),
|
||||||
ExcelCellBase.GetAddress(row, startCol, row, endCol - 1));
|
ExcelCellBase.GetAddress(row, startCol, row, endCol - 1));
|
||||||
|
|
||||||
pieChart.Legend.Position = (eLegendPosition)(int)info.legendPosition;
|
pieChart.Legend.Position = (eLegendPosition)(int)info.legendPosition;
|
||||||
pieChart.DataLabel.ShowPercent = true;
|
pieChart.DataLabel.ShowPercent = true;
|
||||||
|
@ -3,6 +3,7 @@ using COP.Enums;
|
|||||||
using COP.Info;
|
using COP.Info;
|
||||||
using DocumentFormat.OpenXml.EMMA;
|
using DocumentFormat.OpenXml.EMMA;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Linq.Expressions;
|
||||||
using static COP.ExcelComponent;
|
using static COP.ExcelComponent;
|
||||||
|
|
||||||
namespace TestComponents
|
namespace TestComponents
|
||||||
@ -110,63 +111,24 @@ namespace TestComponents
|
|||||||
MessageBox.Show(ex.Message, "Ошибка",
|
MessageBox.Show(ex.Message, "Ошибка",
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class Sportsmen
|
|
||||||
{
|
|
||||||
public string name;
|
|
||||||
public string sport;
|
|
||||||
public string city;
|
|
||||||
public string country;
|
|
||||||
public string Region { get { return city; } set { city = value; } }
|
|
||||||
public string awards;
|
|
||||||
public Sportsmen(string name, string sport, string city, string country, string awards)
|
|
||||||
{
|
|
||||||
this.name = name;
|
|
||||||
this.sport = sport;
|
|
||||||
this.city = city;
|
|
||||||
this.country = country;
|
|
||||||
this.awards = awards;
|
|
||||||
}
|
|
||||||
public Sportsmen() { }
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return country + " " + city + " " + name + " " + sport + " " + awards;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
string[] names = { "Vova M", "Sasha A", "Dima D", "Danila L" };
|
|
||||||
string[] sports = { "Run", "Swim", "Cycle", "Race", "Box" };
|
|
||||||
string[] cities = { "Moskow", "Samara", "Piter", "Kazan", "Kyrsk" };
|
|
||||||
string[] countries = { "Russia", "Spain", "China", "India", "Brazil" };
|
|
||||||
string[] rewards = { "#1", "#2", "KMS", "Olymp", "MS" };
|
|
||||||
List<Employee> sportsmens = new();
|
|
||||||
|
|
||||||
private void buttonSaveTable_Click(object sender, EventArgs e)
|
private void buttonSaveTable_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
ExcelTable table = new();
|
ExcelTable table = new();
|
||||||
string path = @"C:\\Users\\User\\Documents\\testtable.xlsx";
|
var data = new List<Employee>
|
||||||
string title = "title";
|
|
||||||
var dataList = new List<object>
|
|
||||||
{
|
{
|
||||||
new Employee { Id = 1, Status = "Active", Name = "John", Surname = "Doe", Age = "30", Department = "IT", Position = "Manager" },
|
new Employee { Id = 1, Status = "Active", Name = "John", Surname = "Doe", Age = "30", Department = "IT", Position = "Manager" },
|
||||||
new Employee { Id = 2, Status = "Active", Name = "Jane", Surname = "Smith", Age = "35", Department = "Design", Position = "Senior" },
|
new Employee { Id = 2, Status = "Active", Name = "Jane", Surname = "Smith", Age = "35", Department = "Design", Position = "Senior" },
|
||||||
};
|
};
|
||||||
|
Dictionary<string, ((List<string>, List<string>), List<int>)> headers = new()
|
||||||
var info = new ExcelTableInfo(path, "Sample Document", new List<object>(), new Dictionary<string, (List<string>, List<int>)>());
|
{
|
||||||
|
{ "Идентификатор", ((new List<string> { "Id" }, new List<string> {"Идентификатор"} ), new List<int> { 30 } )},
|
||||||
info.addDictionary("Table1", "Field1", 20);
|
{ "Личные данные", ((new List <string> { "Name", "Surname", "Age" }, new List<string> { "Имя", "Фамилия", "Возраст" }), new List<int> { 25, 25, 25 }) },
|
||||||
info.addDictionary("Table1", "Field2", 15);
|
{ "Статус", ((new List<string> { "Status" }, new List<string> { "Статус"}), new List<int> { 30 } )},
|
||||||
info.addDictionary("Table2", "Field1", 25);
|
{ "Работа", ((new List < string > { "Department", "Position" } , new List < string > { "Отдел", "Должность" }), new List<int> { 25, 25 } )}
|
||||||
info.addDictionary("Table2", "Field2", 18);
|
};
|
||||||
info.addDictionary("Table2", "Field3", 22);
|
ExcelTableInfo<Employee> info = new("C:\\Users\\User\\Documents\\testtable.xlsx", "My Document", data, headers);
|
||||||
|
|
||||||
info.addDictionaryAlone("Table3", 30);
|
|
||||||
|
|
||||||
info.Data.Add(new Employee1 { Department = "Dept1", Position = "Position1", Name = "Employee1" });
|
|
||||||
info.Data.Add(new Employee1 { Department = "Dept2", Position = "Position2", Name = "Employee2" });
|
|
||||||
info.Data.Add(new Employee1 { Department = "Dept1", Position = "Position1", Name = "Employee3" });
|
|
||||||
|
|
||||||
dataList.Clear();
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
table.GenerateDocument(info);
|
table.GenerateDocument(info);
|
||||||
@ -177,36 +139,10 @@ namespace TestComponents
|
|||||||
MessageBox.Show(ex.Message, "Ошибка",
|
MessageBox.Show(ex.Message, "Ошибка",
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
/*ExcelTable table = new();
|
|
||||||
|
|
||||||
var mergeInfo = new List<MergeInfo>
|
|
||||||
{
|
|
||||||
new MergeInfo { Value = "", StartRow = 0, EndRow = 0, StartCol = 0, EndCol = 1 },
|
|
||||||
new MergeInfo { Value = "", StartRow = 1, EndRow = 1, StartCol = 0, EndCol = 1 },
|
|
||||||
new MergeInfo { Value = "Личные данные", StartRow = 2, EndRow = 4, StartCol = 0, EndCol = 0 },
|
|
||||||
new MergeInfo { Value = "Работа", StartRow = 5, EndRow = 6, StartCol = 0, EndCol = 0 }
|
|
||||||
};
|
|
||||||
var headerTitles = new List<string> { "ID", "Status", "Name", "Surname", "Age", "Department", "Position" };
|
|
||||||
var data = new List<object>
|
|
||||||
{
|
|
||||||
new Employees { Id = 1, Status = "Active", Name = "John", Surname = "Doe", Age = "30", Department = "IT", Position = "Manager" },
|
|
||||||
new Employees { Id = 2, Status = "Active", Name = "Jane", Surname = "Smith", Age = "35", Department = "Design", Position = "Senior" },
|
|
||||||
};
|
|
||||||
ExcelTableInfo info = new("C:\\Users\\User\\Documents\\testtable.xlsx", "My Document", mergeInfo, headerTitles, data);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
table.GenerateDocument(info);
|
|
||||||
MessageBox.Show("Сохарнено успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка",
|
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Employee
|
public class Employee
|
||||||
{
|
{
|
||||||
public int? Id { get; set; }
|
public int? Id { get; set; }
|
||||||
public string? Status { get; set; } = string.Empty;
|
public string? Status { get; set; } = string.Empty;
|
||||||
public string? Name { get; set; } = string.Empty;
|
public string? Name { get; set; } = string.Empty;
|
||||||
|
Loading…
Reference in New Issue
Block a user