Compare commits

...

5 Commits

26 changed files with 1674 additions and 0 deletions

View File

@ -5,6 +5,13 @@
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" />
<PackageReference Include="EPPlus" Version="6.2.10" />
<PackageReference Include="NPOI" Version="2.6.2" />
</ItemGroup>
</Project>

View File

@ -5,6 +5,8 @@ VisualStudioVersion = 17.3.32825.248
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "COP", "COP.csproj", "{B22B20DB-B359-48B7-88CF-35A6EC770FD1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestComponents", "..\TestComponents\TestComponents.csproj", "{C0F09A72-65A3-49DD-8208-291778E03E81}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -15,6 +17,10 @@ Global
{B22B20DB-B359-48B7-88CF-35A6EC770FD1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B22B20DB-B359-48B7-88CF-35A6EC770FD1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B22B20DB-B359-48B7-88CF-35A6EC770FD1}.Release|Any CPU.Build.0 = Release|Any CPU
{C0F09A72-65A3-49DD-8208-291778E03E81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C0F09A72-65A3-49DD-8208-291778E03E81}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C0F09A72-65A3-49DD-8208-291778E03E81}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C0F09A72-65A3-49DD-8208-291778E03E81}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,10 @@
namespace COP.Enums
{
public enum LegendPosition
{
Top,
Bottom,
Left,
Right
}
}

36
COP/ExcelComponent.Designer.cs generated Normal file
View File

@ -0,0 +1,36 @@
namespace COP
{
partial class ExcelComponent
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}

73
COP/ExcelComponent.cs Normal file
View File

@ -0,0 +1,73 @@
using COP.Info;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System.ComponentModel;
namespace COP
{
public partial class ExcelComponent : Component
{
public ExcelComponent()
{
InitializeComponent();
}
public ExcelComponent(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public void GenerateExcelWithImages(ExcelImageInfo info)
{
if (string.IsNullOrEmpty(info.fileName))
{
throw new ArgumentNullException(nameof(info.fileName), "File name cannot be null or empty.");
}
if (info.images == null || info.images.Count == 0)
{
throw new ArgumentException("At least one image must be provided.", nameof(info.images));
}
if (string.IsNullOrEmpty(info.documentTitle))
{
throw new ArgumentNullException(nameof(info.documentTitle), "Document title cannot be null or empty.");
}
var workbook = new XSSFWorkbook();
var sheet = workbook.CreateSheet("Sheet1");
sheet.CreateRow(0).CreateCell(0).SetCellValue(info.documentTitle);
int startRowIndex = 2;
var rowOffset = 1;
foreach (var imageInfo in info.images)
{
using var fs = new FileStream(imageInfo.FilePath, FileMode.Open, FileAccess.Read);
var imageBytes = new byte[fs.Length];
fs.Read(imageBytes, 0, imageBytes.Length);
var pictureIdx = workbook.AddPicture(imageBytes, PictureType.JPEG);
var drawing = sheet.CreateDrawingPatriarch();
var anchor = new XSSFClientAnchor(0, 0, 0, 0, 0, startRowIndex, 1, startRowIndex + 1);
var picture = drawing.CreatePicture(anchor, pictureIdx);
picture.Resize();
var pictureHeight = picture.GetImageDimension().Height / 20;
startRowIndex += pictureHeight + rowOffset;
}
using (var fs = new FileStream(info.fileName, FileMode.Create, FileAccess.Write))
{
workbook.Write(fs);
}
}
public class ImageInfo
{
public string? FilePath { get; set; }
}
}
}

36
COP/ExcelTable.Designer.cs generated Normal file
View File

@ -0,0 +1,36 @@
namespace COP
{
partial class ExcelTable
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}

175
COP/ExcelTable.cs Normal file
View File

@ -0,0 +1,175 @@
using COP.Info;
using DocumentFormat.OpenXml.EMMA;
using DocumentFormat.OpenXml.Office2010.Excel;
using DocumentFormat.OpenXml.Spreadsheet;
using NPOI.HSSF.Util;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using NPOI.XSSF.UserModel;
using System;
using System.ComponentModel;
using BorderStyle = NPOI.SS.UserModel.BorderStyle;
using HorizontalAlignment = NPOI.SS.UserModel.HorizontalAlignment;
namespace COP
{
public partial class ExcelTable : Component
{
public ExcelTable()
{
InitializeComponent();
}
public ExcelTable(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public void GenerateDocument<T>(ExcelTableInfo<T> info) where T: class
{
if (string.IsNullOrEmpty(info.FilePath))
{
throw new ArgumentException("File path is null or empty.");
}
if (string.IsNullOrEmpty(info.DocumentTitle))
{
throw new ArgumentException("Document title is null or empty.");
}
if (info.Data == null || info.Data.Count == 0)
{
throw new ArgumentException("Data is null or empty.");
}
var workbook = new XSSFWorkbook();
var sheet = workbook.CreateSheet("Sheet1");
sheet.CreateRow(0).CreateCell(0).SetCellValue(info.DocumentTitle);
int curRow = 1;
int curCol = 0;
List<string> headers = new();
var dataCellStyle = GetDataCellStyle(workbook);
var headerCellStyle = GetHeaderCellStyle(workbook);
foreach (var header in info.Headers)
{
headers.Add(header.Key);
var currentRow = sheet.CreateRow(curRow);
var curCell = currentRow.CreateCell(curCol);
if (header.Value.Item1.Item1.Count > 1)
{
sheet.AddMergedRegion(new CellRangeAddress(curRow, curRow + header.Value.Item1.Item1.Count - 1, curCol, curCol));
curCol++;
foreach (var item in header.Value.Item1.Item2)
{
int id = header.Value.Item1.Item2.IndexOf(item);
var cellValue = currentRow.CreateCell(1);
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[0]);
sheet.AddMergedRegion(new CellRangeAddress(curRow, curRow, curCol, curCol + 1));
currentRow.Height = (short)(header.Value.Item2[id] * 20);
curRow++;
}
curCell.SetCellValue(header.Key);
curCell.CellStyle = headerCellStyle;
if (header.Value.Item1.Item1.Count > 1)
{
curCol--;
curRow += header.Value.Item1.Item1.Count;
}
}
curCol = 2;
foreach (var data in info.Data)
{
curRow = 1;
foreach (var header in info.Headers.Values)
{
foreach (var item in header.Item1.Item1)
{
var property = typeof(T).GetProperty(item);
var cellValue = sheet.GetRow(curRow)?.CreateCell(curCol);
if (cellValue != null && property != null)
{
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++;
}
using var fs = new FileStream(info.FilePath, FileMode.Create, FileAccess.Write);
workbook.Write(fs);
}
private static int? GetRowHeight<T>(string header, ExcelTableInfo<T> info) where T:class
{
foreach (var item in info.Headers)
{
foreach (var elem in item.Value.Item1.Item1)
{
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)
{
var style = workbook.CreateCellStyle();
style.BorderBottom = BorderStyle.Thin;
style.BorderLeft = BorderStyle.Thin;
style.BorderRight = BorderStyle.Thin;
style.BorderTop = BorderStyle.Thin;
var font = workbook.CreateFont();
font.Boldweight = (short)FontBoldWeight.Bold;
style.SetFont(font);
style.Alignment = HorizontalAlignment.Center;
style.VerticalAlignment = VerticalAlignment.Center;
return style;
}
private static ICellStyle GetDataCellStyle(IWorkbook workbook)
{
var style = workbook.CreateCellStyle();
style.BorderBottom = BorderStyle.Thin;
style.BorderLeft = BorderStyle.Thin;
style.BorderRight = BorderStyle.Thin;
style.BorderTop = BorderStyle.Thin;
return style;
}
}
public class Property
{
public string? Name { get; set; }
}
}

8
COP/Info/DataItem.cs Normal file
View File

@ -0,0 +1,8 @@
namespace COP.Info
{
public class DataItem
{
public string Name { get; set; } = string.Empty;
public double Value { get; set; }
}
}

View File

@ -0,0 +1,22 @@
using COP.Enums;
namespace COP.Info
{
public class ExcelChartInfo
{
public string? filePath { get; set; } = string.Empty;
public string? documentTitle { get; set; } = string.Empty;
public string? chartTitle { get; set; } = string.Empty;
public LegendPosition legendPosition { get; set; }
public List<DataItem>? data { get; set; }
public ExcelChartInfo(string? filePath, string? documentTitle, string? chartTitle, LegendPosition legendPosition, List<DataItem>? data)
{
this.filePath = filePath;
this.documentTitle = documentTitle;
this.chartTitle = chartTitle;
this.legendPosition = legendPosition;
this.data = data;
}
}
}

View File

@ -0,0 +1,18 @@
using static COP.ExcelComponent;
namespace COP.Info
{
public class ExcelImageInfo
{
public string? fileName { get; set; } = string.Empty;
public string? documentTitle { get; set; } = string.Empty;
public List<ImageInfo>? images { get; set; }
public ExcelImageInfo (string? fileName, string? documentTitle, List<ImageInfo>? images)
{
this.fileName = fileName;
this.documentTitle = documentTitle;
this.images = images;
}
}
}

View File

@ -0,0 +1,18 @@
namespace COP.Info
{
public class ExcelTableInfo<T> where T: class
{
public string FilePath { get; set; } = string.Empty;
public string DocumentTitle { get; set; } = string.Empty;
public List<T>? Data;
public Dictionary<string, ((List<string>, List<string>), List<int>)> Headers { get; set; }
public ExcelTableInfo (string filePath, string documentTitle, List<T> data, Dictionary<string, ((List<string>, List<string>), List<int>)> headers)
{
FilePath = filePath;
DocumentTitle = documentTitle;
Data = data;
Headers = headers;
}
}
}

36
COP/PieChart.Designer.cs generated Normal file
View File

@ -0,0 +1,36 @@
namespace COP
{
partial class PieChart
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}

71
COP/PieChart.cs Normal file
View File

@ -0,0 +1,71 @@
using COP.Info;
using OfficeOpenXml;
using System.ComponentModel;
using LicenseContext = OfficeOpenXml.LicenseContext;
using OfficeOpenXml.Drawing.Chart;
namespace COP
{
public partial class PieChart : Component
{
public PieChart()
{
InitializeComponent();
}
public PieChart(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public void GenerateDocument(ExcelChartInfo info)
{
if (string.IsNullOrEmpty(info.filePath))
{
throw new ArgumentException("File path is null or empty.");
}
if (string.IsNullOrEmpty(info.chartTitle))
{
throw new ArgumentException("Chart title is null or empty.");
}
if (string.IsNullOrEmpty(info.documentTitle))
{
throw new ArgumentException("Document title is null or empty.");
}
if (info.data == null || info.data.Count == 0)
{
throw new ArgumentException("Data is null or empty.");
}
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
using ExcelPackage excelPackage = new();
ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.Add("Sheet 1");
worksheet.Cells["A1"].Value = info.documentTitle;
int row = 2;
int startCol = 1;
int endCol = 1;
foreach (var data in info.data)
{
worksheet.Cells[row, endCol].Value = data.Name;
worksheet.Cells[row + 1, endCol].Value = data.Value;
endCol++;
}
ExcelPieChart? pieChart = worksheet.Drawings.AddChart(info.chartTitle, eChartType.Pie) as ExcelPieChart;
pieChart.Title.Text = info.chartTitle;
pieChart.Series.Add(ExcelCellBase.GetAddress(row + 1, startCol, row + 1, endCol - 1),
ExcelCellBase.GetAddress(row, startCol, row, endCol - 1));
pieChart.Legend.Position = (eLegendPosition)(int)info.legendPosition;
pieChart.DataLabel.ShowPercent = true;
pieChart.SetPosition(1, 0, 0, 0);
FileInfo fi = new(info.filePath);
excelPackage.SaveAs(fi);
}
}
}

58
COP/UserCheckedListBox.Designer.cs generated Normal file
View File

@ -0,0 +1,58 @@
namespace COP
{
partial class UserCheckedListBox
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
this.checkedListBox = new System.Windows.Forms.CheckedListBox();
this.SuspendLayout();
//
// checkedListBox
//
this.checkedListBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.checkedListBox.FormattingEnabled = true;
this.checkedListBox.Location = new System.Drawing.Point(0, 0);
this.checkedListBox.Name = "checkedListBox";
this.checkedListBox.Size = new System.Drawing.Size(150, 150);
this.checkedListBox.TabIndex = 0;
this.checkedListBox.SelectedIndexChanged += new System.EventHandler(this.CheckedListBox_SelectedIndexChanged);
//
// UserCheckedListBox
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.checkedListBox);
this.Name = "UserCheckedListBox";
this.ResumeLayout(false);
}
#endregion
private CheckedListBox checkedListBox;
}
}

68
COP/UserCheckedListBox.cs Normal file
View File

@ -0,0 +1,68 @@
namespace COP
{
public partial class UserCheckedListBox : UserControl
{
private event EventHandler? _selectedValueChanged;
public UserCheckedListBox()
{
InitializeComponent();
}
public void FillList(List<string> items)
{
if (items.Count == 0 || items is null)
{
return;
}
checkedListBox.Items.Clear();
checkedListBox.Items.AddRange(items.ToArray());
}
public void ClearList()
{
checkedListBox.Items.Clear();
}
public string SelectedValue
{
get
{
string checkedItems = "";
for (int i = 0; i < checkedListBox.Items.Count; i++)
{
if (checkedListBox.GetItemChecked(i))
{
checkedItems += checkedListBox.Items[i].ToString() + " ";
}
}
if (checkedListBox.CheckedItems != null)
return checkedItems;
else
return "";
}
set
{
for (int i = 0; i < checkedListBox.Items.Count; i++)
{
if (checkedListBox.Items[i].ToString() == value)
{
checkedListBox.SetItemChecked(i, true);
break;
}
}
}
}
public event EventHandler SelectedValueChanged
{
add { _selectedValueChanged += value; }
remove { _selectedValueChanged += value; }
}
private void CheckedListBox_SelectedIndexChanged(object sender, EventArgs e)
{
_selectedValueChanged?.Invoke(this, e);
}
}
}

61
COP/UserDateTimePicker.Designer.cs generated Normal file
View File

@ -0,0 +1,61 @@
namespace COP
{
partial class UserDateTimePicker
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
this.dateTimePicker = new System.Windows.Forms.DateTimePicker();
this.SuspendLayout();
//
// dateTimePicker
//
this.dateTimePicker.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dateTimePicker.Location = new System.Drawing.Point(0, 3);
this.dateTimePicker.Name = "dateTimePicker";
this.dateTimePicker.Size = new System.Drawing.Size(200, 23);
this.dateTimePicker.TabIndex = 0;
this.dateTimePicker.ValueChanged += new System.EventHandler(this.DateTimePicker_ValueChanged);
//
// UserDateTimePicker
//
this.AccessibleDescription = "";
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.dateTimePicker);
this.Name = "UserDateTimePicker";
this.Size = new System.Drawing.Size(200, 29);
this.ResumeLayout(false);
}
#endregion
private DateTimePicker dateTimePicker;
}
}

100
COP/UserDateTimePicker.cs Normal file
View File

@ -0,0 +1,100 @@
namespace COP
{
public partial class UserDateTimePicker : UserControl
{
private DateTime? minValue;
private DateTime? maxValue;
public event EventHandler? _valueChanged;
private event Action? _errorOccured;
public string Error { get; private set; }
public UserDateTimePicker()
{
InitializeComponent();
Error = string.Empty;
}
public DateTime? MinValue
{
get { return minValue; }
set { minValue = value; }
}
public DateTime? MaxValue
{
get { return maxValue; }
set { maxValue = value; }
}
public DateTime? SelectedValue
{
get
{
if (!minValue.HasValue || !maxValue.HasValue)
{
Error = "Range is not set.";
_errorOccured?.Invoke();
return null;
}
else if (dateTimePicker.Value < minValue ||
dateTimePicker.Value > maxValue)
{
Error = "Selected value is out of range.";
_errorOccured?.Invoke();
return null;
}
return dateTimePicker.Value;
}
set
{
if (!value.HasValue)
{
Error = "Value is null.";
_errorOccured?.Invoke();
return;
}
if (!minValue.HasValue || !maxValue.HasValue)
{
Error = "Range is not set.";
_errorOccured?.Invoke();
return;
}
if (value < minValue || value > maxValue)
{
Error = "Selected value is out of range.";
_errorOccured?.Invoke();
return;
}
dateTimePicker.Value = value.Value;
}
}
public event EventHandler ValueChanged
{
add { _valueChanged += value; }
remove { _valueChanged -= value; }
}
public event Action AnErrorOccurred
{
add { _errorOccured += value; }
remove { _errorOccured -= value; }
}
private void DateTimePicker_ValueChanged(object sender, EventArgs e)
{
try
{
_valueChanged?.Invoke(this, e);
}
catch (Exception ex)
{
Error = ex.Message;
_errorOccured?.Invoke();
}
}
}
}

120
COP/UserDateTimePicker.resx Normal file
View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

56
COP/UserTreeView.Designer.cs generated Normal file
View File

@ -0,0 +1,56 @@
namespace COP
{
partial class UserTreeView
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
this.treeView = new System.Windows.Forms.TreeView();
this.SuspendLayout();
//
// treeView
//
this.treeView.Dock = System.Windows.Forms.DockStyle.Fill;
this.treeView.Location = new System.Drawing.Point(0, 0);
this.treeView.Name = "treeView";
this.treeView.Size = new System.Drawing.Size(150, 150);
this.treeView.TabIndex = 0;
//
// UserTreeView
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.treeView);
this.Name = "UserTreeView";
this.ResumeLayout(false);
}
#endregion
private TreeView treeView;
}
}

103
COP/UserTreeView.cs Normal file
View File

@ -0,0 +1,103 @@
using System.Xml;
namespace COP
{
public partial class UserTreeView : UserControl
{
private event Action? _errorOccured;
public List<string> Hierarchy;
public string Error { get; private set; }
public UserTreeView()
{
InitializeComponent();
Error = string.Empty;
Hierarchy = new();
}
// иерархия
// метод заполнения иерархии
public event Action AnErrorOccurred
{
add { _errorOccured += value; }
remove { _errorOccured -= value; }
}
public int SelectedItemIndex
{
get
{
if (treeView.SelectedNode == null)
{
return -1;
}
return treeView.SelectedNode.Index;
}
}
public T? GetSelectedObject<T>() where T : class, new()
{
// параметризованный
//проверка есть или нет иерархии
TreeNode selectedNode = treeView.SelectedNode;
if (Hierarchy == null)
{
throw new Exception("Hierarchy is not set.");
}
if (selectedNode?.FirstNode != null)
{
throw new Exception("Not a last level node.");
}
T currentBranch = new T();
Hierarchy.Reverse();
foreach (var property in Hierarchy)
{
typeof(T).GetProperty(property).SetValue(currentBranch, Convert.ChangeType(selectedNode.Text, typeof(T).GetProperty(property).PropertyType));
selectedNode = selectedNode.Parent;
}
Hierarchy.Reverse();
return currentBranch;
}
//проверка что выбранный элем последний в ветке
public void PopulateTree<T>(List<T> items)
{
treeView.BeginUpdate();
treeView.Nodes.Clear();
if (items == null)
{
throw new ArgumentNullException(nameof(items));
}
if (Hierarchy == null)
{
throw new Exception("Hierarchy is not set.");
}
foreach (var item in items)
{
TreeNodeCollection treeViewNodes = treeView.Nodes;
foreach (var elem in Hierarchy)
{
bool flag = false;
for (int i = 0; i < treeViewNodes.Count; i++)
{
if (item.GetType().GetProperty(elem).GetValue(item).ToString() == treeViewNodes[i].Text)
{
treeViewNodes = treeViewNodes[i].Nodes;
flag = true;
break;
}
}
if (!flag)
{
var newNode = treeViewNodes.Add(item.GetType().GetProperty(elem).GetValue(item).ToString());
treeViewNodes = newNode.Nodes;
}
}
}
treeView.EndUpdate();
}
}
}

120
COP/UserTreeView.resx Normal file
View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,191 @@
namespace TestComponents
{
partial class FormTestComponents
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.userCheckedListBox = new COP.UserCheckedListBox();
this.userDateTimePicker = new COP.UserDateTimePicker();
this.userTreeView = new COP.UserTreeView();
this.buttonClear = new System.Windows.Forms.Button();
this.textBoxItems = new System.Windows.Forms.TextBox();
this.buttonShowItems = new System.Windows.Forms.Button();
this.textBoxShowDate = new System.Windows.Forms.TextBox();
this.buttonShowDate = new System.Windows.Forms.Button();
this.excelComponent = new COP.ExcelComponent(this.components);
this.buttonSaveToExcel = new System.Windows.Forms.Button();
this.buttonSaveTable = new System.Windows.Forms.Button();
this.excelTable = new COP.ExcelTable(this.components);
this.buttonSaveChart = new System.Windows.Forms.Button();
this.pieChart = new COP.PieChart(this.components);
this.SuspendLayout();
//
// userCheckedListBox
//
this.userCheckedListBox.Location = new System.Drawing.Point(0, -1);
this.userCheckedListBox.Name = "userCheckedListBox";
this.userCheckedListBox.SelectedValue = "";
this.userCheckedListBox.Size = new System.Drawing.Size(150, 150);
this.userCheckedListBox.TabIndex = 0;
this.userCheckedListBox.SelectedValueChanged += new System.EventHandler(this.UserCheckedListBox_SelectedValueChanged);
//
// userDateTimePicker
//
this.userDateTimePicker.AccessibleDescription = "";
this.userDateTimePicker.Location = new System.Drawing.Point(254, 26);
this.userDateTimePicker.MaxValue = null;
this.userDateTimePicker.MinValue = null;
this.userDateTimePicker.Name = "userDateTimePicker";
this.userDateTimePicker.SelectedValue = null;
this.userDateTimePicker.Size = new System.Drawing.Size(200, 29);
this.userDateTimePicker.TabIndex = 1;
this.userDateTimePicker.ValueChanged += new System.EventHandler(this.UserDateTimePicker_ValueChanged);
//
// userTreeView
//
this.userTreeView.Location = new System.Drawing.Point(484, 26);
this.userTreeView.Name = "userTreeView";
this.userTreeView.Size = new System.Drawing.Size(150, 150);
this.userTreeView.TabIndex = 2;
this.userTreeView.Load += new System.EventHandler(this.UserTreeView_Load);
//
// buttonClear
//
this.buttonClear.Location = new System.Drawing.Point(0, 164);
this.buttonClear.Name = "buttonClear";
this.buttonClear.Size = new System.Drawing.Size(75, 23);
this.buttonClear.TabIndex = 3;
this.buttonClear.Text = "Очистить";
this.buttonClear.UseVisualStyleBackColor = true;
this.buttonClear.Click += new System.EventHandler(this.ButtonClear_Click);
//
// textBoxItems
//
this.textBoxItems.Location = new System.Drawing.Point(0, 205);
this.textBoxItems.Name = "textBoxItems";
this.textBoxItems.Size = new System.Drawing.Size(150, 23);
this.textBoxItems.TabIndex = 4;
//
// buttonShowItems
//
this.buttonShowItems.Location = new System.Drawing.Point(0, 250);
this.buttonShowItems.Name = "buttonShowItems";
this.buttonShowItems.Size = new System.Drawing.Size(125, 23);
this.buttonShowItems.TabIndex = 5;
this.buttonShowItems.Text = "Вывести значения";
this.buttonShowItems.UseVisualStyleBackColor = true;
this.buttonShowItems.Click += new System.EventHandler(this.ButtonShowItems_Click);
//
// textBoxShowDate
//
this.textBoxShowDate.Location = new System.Drawing.Point(269, 79);
this.textBoxShowDate.Name = "textBoxShowDate";
this.textBoxShowDate.Size = new System.Drawing.Size(150, 23);
this.textBoxShowDate.TabIndex = 6;
//
// buttonShowDate
//
this.buttonShowDate.Location = new System.Drawing.Point(269, 139);
this.buttonShowDate.Name = "buttonShowDate";
this.buttonShowDate.Size = new System.Drawing.Size(125, 23);
this.buttonShowDate.TabIndex = 7;
this.buttonShowDate.Text = "Вывести значения";
this.buttonShowDate.UseVisualStyleBackColor = true;
this.buttonShowDate.Click += new System.EventHandler(this.ButtonShowDate_Click);
//
// buttonSaveToExcel
//
this.buttonSaveToExcel.Location = new System.Drawing.Point(236, 240);
this.buttonSaveToExcel.Name = "buttonSaveToExcel";
this.buttonSaveToExcel.Size = new System.Drawing.Size(158, 23);
this.buttonSaveToExcel.TabIndex = 8;
this.buttonSaveToExcel.Text = "Сохранить картинки";
this.buttonSaveToExcel.UseVisualStyleBackColor = true;
this.buttonSaveToExcel.Click += new System.EventHandler(this.buttonSaveToExcel_Click);
//
// buttonSaveTable
//
this.buttonSaveTable.Location = new System.Drawing.Point(412, 240);
this.buttonSaveTable.Name = "buttonSaveTable";
this.buttonSaveTable.Size = new System.Drawing.Size(158, 23);
this.buttonSaveTable.TabIndex = 9;
this.buttonSaveTable.Text = "Сохранить таблицу";
this.buttonSaveTable.UseVisualStyleBackColor = true;
this.buttonSaveTable.Click += new System.EventHandler(this.buttonSaveTable_Click);
//
// buttonSaveChart
//
this.buttonSaveChart.Location = new System.Drawing.Point(318, 269);
this.buttonSaveChart.Name = "buttonSaveChart";
this.buttonSaveChart.Size = new System.Drawing.Size(158, 23);
this.buttonSaveChart.TabIndex = 10;
this.buttonSaveChart.Text = "Сохранить диаграмму";
this.buttonSaveChart.UseVisualStyleBackColor = true;
this.buttonSaveChart.Click += new System.EventHandler(this.buttonSaveChart_Click);
//
// FormTestComponents
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(657, 321);
this.Controls.Add(this.buttonSaveChart);
this.Controls.Add(this.buttonSaveTable);
this.Controls.Add(this.buttonSaveToExcel);
this.Controls.Add(this.buttonShowDate);
this.Controls.Add(this.textBoxShowDate);
this.Controls.Add(this.buttonShowItems);
this.Controls.Add(this.textBoxItems);
this.Controls.Add(this.buttonClear);
this.Controls.Add(this.userTreeView);
this.Controls.Add(this.userDateTimePicker);
this.Controls.Add(this.userCheckedListBox);
this.Name = "FormTestComponents";
this.Text = "Тестовая форма";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private COP.UserCheckedListBox userCheckedListBox;
private COP.UserDateTimePicker userDateTimePicker;
private COP.UserTreeView userTreeView;
private Button buttonClear;
private TextBox textBoxItems;
private Button buttonShowItems;
private TextBox textBoxShowDate;
private Button buttonShowDate;
private COP.ExcelComponent excelComponent;
private Button buttonSaveToExcel;
private Button buttonSaveTable;
private COP.ExcelTable excelTable;
private Button buttonSaveChart;
private COP.PieChart pieChart;
}
}

View File

@ -0,0 +1,180 @@
using COP;
using COP.Enums;
using COP.Info;
using DocumentFormat.OpenXml.EMMA;
using System.ComponentModel;
using System.Linq.Expressions;
using static COP.ExcelComponent;
namespace TestComponents
{
public partial class FormTestComponents : Form
{
public FormTestComponents()
{
InitializeComponent();
Fill();
}
private void Fill()
{
List<string> items = new() { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
userCheckedListBox.FillList(items);
}
private void UserCheckedListBox_SelectedValueChanged(object sender, EventArgs e)
{
MessageBox.Show("Selected value changed");
}
private void ButtonClear_Click(object sender, EventArgs e)
{
userCheckedListBox.ClearList();
}
private void ButtonShowItems_Click(object sender, EventArgs e)
{
textBoxItems.Clear();
textBoxItems.Text = userCheckedListBox.SelectedValue;
}
private void ButtonShowDate_Click(object sender, EventArgs e)
{
try
{
textBoxShowDate.Clear();
textBoxShowDate.Text = userDateTimePicker.SelectedValue.ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void UserDateTimePicker_ValueChanged(object sender, EventArgs e)
{
MessageBox.Show("Value changed");
DateTime? selectedDate = userDateTimePicker.SelectedValue;
}
private void UserTreeView_Load(object sender, EventArgs e)
{
List<Employee1> employees = new()
{
new Employee1 { Department = "Отдел1", Position = олжность1", Name = "Сотрудник1" },
new Employee1 { Department = "Отдел2", Position = олжность2", Name = "Сотрудник2" },
new Employee1 { Department = "Отдел1", Position = олжность1", Name = "Сотрудник3" },
new Employee1 { Department = "Отдел2", Position = олжность3", Name = "Сотрудник4" },
};
var Hierarchy = new List<string> { "Department", "Position", "Name" };
foreach (var prop in employees[0].GetType().GetProperties())
{
userTreeView.Hierarchy.Add(prop.Name);
}
try
{
userTreeView.PopulateTree(employees);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public class Employee1
{
public string? Department { get; set; }
public string? Position { get; set; }
public string? Name { get; set; }
}
private void buttonSaveToExcel_Click(object sender, EventArgs e)
{
ExcelComponent excel = new();
List<ImageInfo> images = new()
{
new ImageInfo() { FilePath = "C:\\Users\\User\\Documents\\image1.jpg" },
new ImageInfo() { FilePath = "C:\\Users\\User\\Documents\\image2.jpg" },
new ImageInfo() { FilePath = "C:\\Users\\User\\Documents\\image3.jpg" }
};
ExcelImageInfo info = new("C:\\Users\\User\\Documents\\test.xlsx", "My Document", images);
try
{
excel.GenerateExcelWithImages(info);
MessageBox.Show("Сохарнено успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonSaveTable_Click(object sender, EventArgs e)
{
ExcelTable table = new();
var data = new List<Employee>
{
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" },
};
Dictionary<string, ((List<string>, List<string>), List<int>)> headers = new()
{
{ "Идентификатор", ((new List<string> { "Id" }, new List<string> {"Идентификатор"} ), new List<int> { 30 } )},
{ "Личные данные", ((new List <string> { "Name", "Surname", "Age" }, new List<string> { "Имя", "Фамилия", "Возраст" }), new List<int> { 25, 25, 25 }) },
{ "Статус", ((new List<string> { "Status" }, new List<string> { "Статус"}), new List<int> { 30 } )},
{ "Работа", ((new List < string > { "Department", "Position" } , new List < string > { "Отдел", "Должность" }), new List<int> { 25, 25 } )}
};
ExcelTableInfo<Employee> info = new("C:\\Users\\User\\Documents\\testtable.xlsx", "My Document", data, headers);
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 int? Id { get; set; }
public string? Status { get; set; } = string.Empty;
public string? Name { get; set; } = string.Empty;
public string? Surname { get; set; } = string.Empty;
public string? Age { get; set; } = string.Empty;
public string? Department { get; set; } = string.Empty;
public string? Position { get; set; } = string.Empty;
}
private void buttonSaveChart_Click(object sender, EventArgs e)
{
PieChart chart = new();
LegendPosition legend = new();
var data = new List<DataItem>()
{
new DataItem() { Name = "Data 1", Value = 10 },
new DataItem() { Name = "Data 2", Value = 20 },
new DataItem() { Name = "Data 3", Value = 30 },
new DataItem() { Name = "Data 4", Value = 40 }
};
ExcelChartInfo info = new("C:\\Users\\User\\Documents\\testchart.xlsx", "My Document", "My Chart", legend, data);
try
{
chart.GenerateDocument(info);
MessageBox.Show("Сохарнено успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -0,0 +1,69 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="excelComponent.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="excelTable.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>160, 17</value>
</metadata>
<metadata name="pieChart.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>268, 17</value>
</metadata>
</root>

17
TestComponents/Program.cs Normal file
View File

@ -0,0 +1,17 @@
namespace TestComponents
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormTestComponents());
}
}
}

View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\COP\COP.csproj" />
</ItemGroup>
</Project>