Compare commits

...

8 Commits
main ... Lab2

17 changed files with 757 additions and 25 deletions

View File

@ -6,6 +6,12 @@
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Aspose.Words" Version="23.10.0" />
<PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" />
</ItemGroup>
</Project>

36
COPWinForms/ComponentWord1.Designer.cs generated Normal file
View File

@ -0,0 +1,36 @@
namespace COPWinForms
{
partial class ComponentWord1
{
/// <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
}
}

View File

@ -0,0 +1,88 @@
using Aspose.Words;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace COPWinForms
{
public partial class ComponentWord1 : Component
{
private string _fileName;
public string FileName
{
set
{
if (string.IsNullOrEmpty(value))
{
return;
}
if (!value.EndsWith(".docx"))
{
throw new ArgumentException("No docx file");
}
_fileName = value;
}
}
public ComponentWord1()
{
InitializeComponent();
_fileName = string.Empty;
}
public ComponentWord1(IContainer container)
{
container.Add(this);
InitializeComponent();
_fileName = string.Empty;
}
public void CreateWordText(TextWord textWord)
{
if (string.IsNullOrEmpty(textWord.FilePath) || string.IsNullOrEmpty(textWord.DocumentTitle) || !CheckData(textWord.TextData))
{
throw new Exception("Не все данные заполнены");
}
// Создание документа
Document document = new Document();
DocumentBuilder builder = new DocumentBuilder(document);
Style titleStyle = builder.Document.Styles.Add(StyleType.Paragraph, "Title");
titleStyle.Font.Size = 16;
titleStyle.Font.Bold = true;
// Установка заголовка документа
builder.ParagraphFormat.Style = titleStyle;
builder.Writeln(textWord.DocumentTitle);
// Создание обычного стиля для остального текста
Style normalStyle = builder.Document.Styles[StyleIdentifier.Normal];
normalStyle.Font.Size = 12;
// Применение обычного стиля для остального текста
builder.ParagraphFormat.Style = normalStyle;
// Установка заголовка документа
document.BuiltInDocumentProperties.Title = textWord.DocumentTitle;
foreach (string textLine in textWord.TextData)
{
// Добавление строки текста в документ
builder.Writeln(textLine);
}
document.Save(textWord.FilePath);
}
bool CheckData(string[] data)
{
for (int i = 0; i < data.Length; i++)
{
if (string.IsNullOrEmpty(data[i])) return false;
}
return true;
}
}
}

36
COPWinForms/ComponentWord2.Designer.cs generated Normal file
View File

@ -0,0 +1,36 @@
namespace COPWinForms
{
partial class ComponentWord2
{
/// <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
}
}

View File

@ -0,0 +1,176 @@
using Aspose.Words.Drawing.Charts;
using Aspose.Words;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aspose.Words.Tables;
using static COPWinForms.ComponentWord2;
namespace COPWinForms
{
public partial class ComponentWord2 : Component
{
private string _fileName;
public string FileName
{
set
{
if (string.IsNullOrEmpty(value))
{
return;
}
if (!value.EndsWith(".docx"))
{
throw new ArgumentException("No docx file");
}
_fileName = value;
}
}
public ComponentWord2()
{
InitializeComponent();
}
public ComponentWord2(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public void CreateTable<T>(TableWord<T> tableWord) where T : class
{
// Проверка наличия данных и определений столбцов
if (tableWord.Data == null)
{
throw new ArgumentException("Data or column definitions are null or empty");
}
// Проверка, что все ячейки шапки заполнены и для каждого столбца определено свойство/поле класса
foreach (var columnDefinition in tableWord.ColumnDefinitions)
{
if (string.IsNullOrEmpty(columnDefinition.PropertyName))
{
throw new ArgumentException($"Incomplete column definition: {columnDefinition.Header}");
}
}
// Создание документа
Document document = new Document();
DocumentBuilder builder = new DocumentBuilder(document);
Style titleStyle = builder.Document.Styles.Add(StyleType.Paragraph, "Title");
titleStyle.Font.Size = 16;
titleStyle.Font.Bold = true;
// Установка заголовка документа
builder.ParagraphFormat.Style = titleStyle;
builder.Writeln(tableWord.DocumentTitle);
// Создание таблицы
Table table = builder.StartTable();
int ColInd1 = 0;
foreach (var columnDefinition in tableWord.ColumnDefinitions)
{
builder.InsertCell();
builder.CellFormat.PreferredWidth = PreferredWidth.FromPoints(columnDefinition.Width);
builder.Write(columnDefinition.Header);
ColInd1++;
}
// Объединение ячеек в первой строке шапки таблицы
foreach (var mergedColumn in tableWord.MergedColumns)
{
int startCellIndex = mergedColumn[0];
int endCellIndex = mergedColumn[mergedColumn.Length - 1];
// Объединение ячеек в первой строке шапки таблицы
for (int i = startCellIndex; i <= endCellIndex; i++)
{
table.Rows[0].Cells[i].CellFormat.HorizontalMerge = CellMerge.First;
}
// Если столбцов для объединения больше одного, то нужно объединять остальные ячейки в первой строке
if (endCellIndex - startCellIndex > 0)
{
for (int i = startCellIndex + 1; i <= endCellIndex; i++)
{
table.Rows[0].Cells[i].CellFormat.HorizontalMerge = CellMerge.Previous;
}
}
}
builder.EndRow();
int ColInd = 0;
foreach (var columnDefinition2 in tableWord.ColumnDefinitions2)
{
builder.InsertCell();
builder.CellFormat.PreferredWidth = PreferredWidth.FromPoints(columnDefinition2.Width);
builder.Write(columnDefinition2.Header);
ColInd++;
}
builder.EndRow();
int columnIndex;
foreach (var columnDefinition in tableWord.ColumnDefinitions)
{
string currentPropertyName = columnDefinition.PropertyName;
columnIndex = 0;
foreach (var columnDefinition2 in tableWord.ColumnDefinitions2)
{
string currentPropertyName1 = columnDefinition2.PropertyName;
if (currentPropertyName == currentPropertyName1)
{
table.Rows[0].Cells[columnIndex].CellFormat.VerticalMerge = CellMerge.First;
table.Rows[1].Cells[columnIndex].CellFormat.VerticalMerge = CellMerge.Previous;
}
columnIndex++;
}
}
// Вставка данных в таблицу
foreach (var item in tableWord.Data)
{
foreach (var columnDefinition2 in tableWord.ColumnDefinitions2)
{
builder.InsertCell();
// Получение значения свойства/поля объекта по заданному имени
var propertyValue = item.GetType()
.GetProperty(columnDefinition2.PropertyName)?
.GetValue(item)?.ToString();
// Вставка значения в ячейку
builder.Write(propertyValue ?? "");
}
builder.EndRow();
}builder.EndTable();
// Сохранение документа в файл
document.Save(tableWord.FilePath);
}
public class ColumnDefinition
{
public string Header { get; set; }
public string PropertyName { get; set; }
public int Width { get; set; }
}
}
}

36
COPWinForms/ComponentWord3.Designer.cs generated Normal file
View File

@ -0,0 +1,36 @@
namespace COPWinForms
{
partial class ComponentWord3
{
/// <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
}
}

View File

@ -0,0 +1,87 @@
using Aspose.Words.Drawing.Charts;
using Aspose.Words;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using Aspose.Words.Drawing;
using DocumentFormat.OpenXml.Office2010.Excel;
namespace COPWinForms
{
public partial class ComponentWord3 : Component
{
private string _fileName;
public string FileName
{
set
{
if (string.IsNullOrEmpty(value))
{
return;
}
if (!value.EndsWith(".docx"))
{
throw new ArgumentException("No docx file");
}
_fileName = value;
}
}
public ComponentWord3()
{
InitializeComponent();
}
public ComponentWord3(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public void CreateLineChart(DiagramWord diagramWord)
{
// Проверка наличия заголовка, пути и названия диаграммы
if (string.IsNullOrEmpty(diagramWord.ChartTitle) || string.IsNullOrEmpty(diagramWord.FilePath) || string.IsNullOrEmpty(diagramWord.DocumentTitle))
{
throw new ArgumentException("Chart title is null or empty");
}
// Создание документа
Document document = new Document();
DocumentBuilder builder = new DocumentBuilder(document);
Style titleStyle = builder.Document.Styles.Add(StyleType.Paragraph, "Title");
titleStyle.Font.Size = 16;
titleStyle.Font.Bold = true;
// Установка заголовка документа
builder.ParagraphFormat.Style = titleStyle;
builder.Writeln(diagramWord.DocumentTitle);
// Вставка диаграммы
Shape chartShape = builder.InsertChart(ChartType.Line, 400, 300);
Chart chart = chartShape.Chart;
// Настройка заголовка диаграммы
ChartTitle title = chart.Title;
title.Text = diagramWord.ChartTitle;
ChartSeriesCollection seriesColl = chart.Series;
seriesColl.Clear();
// Создание и заполнение коллекции категорий
foreach (var diagramDatas in diagramWord.DiagramDatas)
{
seriesColl.Add(diagramDatas.Seria, diagramWord.Category, diagramDatas.Data);
}
chart.Legend.Position = (Aspose.Words.Drawing.Charts.LegendPosition)diagramWord.LegendPosition;
// Сохранение документа в файл
document.Save(diagramWord.FilePath);
}
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace COPWinForms
{
public class DiagramData
{
public string Seria = string.Empty;
public double[] Data;
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static COPWinForms.ComponentWord2;
namespace COPWinForms
{
public class DiagramWord
{
public string FilePath = string.Empty;
public string DocumentTitle = string.Empty;
public string ChartTitle = string.Empty;
public LegendPosition LegendPosition;
public List<DiagramData> DiagramDatas;
public string[] Category;
public DiagramWord(string filePath, string documentTitle, string chartTitle, LegendPosition legendPosition, List<DiagramData> diagramDatas, string[] category)
{
FilePath = filePath;
DocumentTitle = documentTitle;
ChartTitle = chartTitle;
LegendPosition = legendPosition;
DiagramDatas = diagramDatas;
Category = category;
}
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace COPWinForms
{
public enum LegendPosition
{
Top,
Bottom,
Left,
Right
}
}

View File

@ -11,12 +11,14 @@ namespace COPWinForms
public string FIO { get; set; }
public string Group { get; set; }
public string Email { get; set; }
public string Adress { get; set; }
public Student(string fIO, string group, string email)
public Student(string fIO, string group, string email, string adress)
{
FIO = fIO;
Group = group;
Email = email;
Adress = adress;
}
public Student() { }

28
COPWinForms/TableWord.cs Normal file
View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static COPWinForms.ComponentWord2;
namespace COPWinForms
{
public class TableWord<T> where T : class
{
public string FilePath = string.Empty;
public string DocumentTitle = string.Empty;
public List<ColumnDefinition> ColumnDefinitions;
public List<ColumnDefinition> ColumnDefinitions2;
public List<T> Data;
public List<int[]> MergedColumns;
public TableWord(string filePath, string documentTitle, List<ColumnDefinition> columnDefinitions, List<ColumnDefinition> columnDefinitions2, List<T> data, List<int[]> mergedColumns)
{
FilePath = filePath;
DocumentTitle = documentTitle;
ColumnDefinitions = columnDefinitions;
ColumnDefinitions2 = columnDefinitions2;
Data = data;
MergedColumns = mergedColumns;
}
}
}

24
COPWinForms/TextWord.cs Normal file
View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace COPWinForms
{
public class TextWord
{
public string FilePath = string.Empty;
public string DocumentTitle = string.Empty;
public string[] TextData;
public TextWord(string filePath, string documentTitle, string[] textData)
{
FilePath = filePath;
DocumentTitle = documentTitle;
TextData = textData;
}
}
}

View File

@ -3,11 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32825.248
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "COP_1", "COP_1.csproj", "{3A354E62-6788-412B-8F8F-5A3484373BDA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "COPWinForms", "..\COPWinForms\COPWinForms.csproj", "{C88D51BC-B17E-40DD-BC69-480DD08ED488}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsTest", "..\WinFormsTest\WinFormsTest.csproj", "{75E77B58-7C69-4C52-8283-03EBC03D2C85}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormsTest", "..\WinFormsTest\WinFormsTest.csproj", "{75E77B58-7C69-4C52-8283-03EBC03D2C85}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -15,10 +13,6 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3A354E62-6788-412B-8F8F-5A3484373BDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3A354E62-6788-412B-8F8F-5A3484373BDA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3A354E62-6788-412B-8F8F-5A3484373BDA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3A354E62-6788-412B-8F8F-5A3484373BDA}.Release|Any CPU.Build.0 = Release|Any CPU
{C88D51BC-B17E-40DD-BC69-480DD08ED488}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C88D51BC-B17E-40DD-BC69-480DD08ED488}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C88D51BC-B17E-40DD-BC69-480DD08ED488}.Release|Any CPU.ActiveCfg = Release|Any CPU

View File

@ -28,6 +28,7 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
@ -41,6 +42,12 @@
this.componentlBox1 = new COPWinForms.ComponentLBox();
this.textBoxShowItem = new System.Windows.Forms.TextBox();
this.componentcBox1 = new COPWinForms.ComponentCBox();
this.componentWord11 = new COPWinForms.ComponentWord1(this.components);
this.buttonSave1 = new System.Windows.Forms.Button();
this.componentWord31 = new COPWinForms.ComponentWord3(this.components);
this.button2 = new System.Windows.Forms.Button();
this.componentWord21 = new COPWinForms.ComponentWord2(this.components);
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
@ -131,6 +138,7 @@
this.componenttBox1.Pattern = null;
this.componenttBox1.Size = new System.Drawing.Size(188, 46);
this.componenttBox1.TabIndex = 16;
this.componenttBox1.TextBoxValue = null;
//
// componentlBox1
//
@ -156,11 +164,44 @@
this.componentcBox1.TabIndex = 19;
this.componentcBox1.CursorChanged += new System.EventHandler(this.componentcBox1_ExplicitEvent);
//
// buttonSave1
//
this.buttonSave1.Location = new System.Drawing.Point(161, 307);
this.buttonSave1.Name = "buttonSave1";
this.buttonSave1.Size = new System.Drawing.Size(147, 29);
this.buttonSave1.TabIndex = 20;
this.buttonSave1.Text = "Сохранить 1";
this.buttonSave1.UseVisualStyleBackColor = true;
this.buttonSave1.Click += new System.EventHandler(this.buttonSave1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(603, 307);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(147, 29);
this.button2.TabIndex = 21;
this.button2.Text = "Сохранить 3";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(385, 307);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(147, 29);
this.button3.TabIndex = 22;
this.button3.Text = "Сохранить 2";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// FormTestApp
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1027, 288);
this.ClientSize = new System.Drawing.Size(1027, 384);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.buttonSave1);
this.Controls.Add(this.componentcBox1);
this.Controls.Add(this.textBoxShowItem);
this.Controls.Add(this.componentlBox1);
@ -193,6 +234,12 @@
private COPWinForms.ComponentLBox componentlBox1;
private TextBox textBoxShowItem;
private COPWinForms.ComponentCBox componentcBox1;
private COPWinForms.ComponentWord1 componentWord11;
private Button buttonSave1;
private COPWinForms.ComponentWord3 componentWord31;
private Button button2;
private COPWinForms.ComponentWord2 componentWord21;
private Button button3;
}
#endregion

View File

@ -1,6 +1,8 @@
using COPWinForms;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using static COPWinForms.ComponentWord2;
namespace WinFormsTest
{
@ -8,15 +10,18 @@ namespace WinFormsTest
{
List<string> list = new List<string>();
List<Student> students = new List<Student>();
List<string> listToSave = new List<string>();
string[] testArray = { "Ó êîìïîíåíòà äîëæåí áûòü ïóáëè÷íûé ìåòîä", "ÀÀÀÀ ÝÒÎ ÐÀÁÎÒÀÅÒ", "yes" };
public FormTestApp()
{
list = new List<string>();
list.AddRange(new string[] { "Çíà÷åíèå 1", "Çíà÷åíèå 2", "Çíà÷åíèå 3", "Çíà÷åíèå 4", "Çíà÷åíèå 5" });
Student student1 = new Student("Ðîãàøîâà Å.À.", "ÏÈáä-32", "rogashovae@mail.ru");
Student student2 = new Student("Ïåòðîâ Ï.Â.", "Ýóáä-11", "petrov@gmail.com");
Student student3 = new Student("Íîñêîâà À.À.", "ÏÌáä-41", "noskovaaa@gmail.com");
Student student4 = new Student("Íîñêîâ À.À.", "ÏCáä-41", "noskovaa@gmail.com");
Student student1 = new Student("Ðîãàøîâà Å.À.", "ÏÈáä-32", "rogashovae@mail.ru", "");
Student student2 = new Student("Ïåòðîâ Ï.Â.", "Ýóáä-11", "petrov@gmail.com", "");
Student student3 = new Student("Íîñêîâà À.À.", "ÏÌáä-41", "noskovaaa@gmail.com", "");
Student student4 = new Student("Íîñêîâ À.À.", "ÏCáä-41", "noskovaa@gmail.com", "");
students.Add(student1);
students.Add(student2);
@ -31,6 +36,10 @@ namespace WinFormsTest
componentcBox1.ExplicitEvent += Event_Handler;
componenttBox1.ExplicitEvent += Event_Handler;
componenttBox1.setExample("eeee@mail.ru");
componentWord11.FileName = "E:\\1.docx";
}
private void buttonAdd_Click(object sender, EventArgs e)
@ -53,16 +62,6 @@ namespace WinFormsTest
componentcBox1.Clear();
}
//private void buttonSetExample_Click(object sender, EventArgs e)
//{
// if (textBoxExample.Text == String.Empty)
// {
// return;
// }
// componenttBox1.setExample(textBoxExample.Text);
//}
private void buttonShowTB_Click(object sender, EventArgs e)
{
try
@ -76,8 +75,6 @@ namespace WinFormsTest
{
MessageBox.Show(ex.Message);
}
}
private void button1_Click(object sender, EventArgs e)
@ -94,5 +91,110 @@ namespace WinFormsTest
{
MessageBox.Show("Change avatar");
}
private void buttonSave1_Click(object sender, EventArgs e)
{
//ôèëüòðàöèÿ ôàéëîâ äëÿ äèàëîãîâîãî îêíà
using var dialog = new SaveFileDialog
{
Filter = "docx|*.docx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
TextWord textWord = new(dialog.FileName, "Çàäàíèå 1", testArray);
componentWord11.CreateWordText(textWord);
MessageBox.Show("Âûïîëíåíî", "Óñïåõ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void button2_Click(object sender, EventArgs e)
{
ComponentWord3 chartComponent = new ComponentWord3();
string[] categories = new string[] { "Category1", "Category2"};
List<DiagramData> diagramData = new List<DiagramData>
{
new DiagramData { Seria = "Seria1", Data = new double[]{ 1, 20}},
new DiagramData { Seria = "Seria2", Data = new double[]{ 10, 17}},
new DiagramData { Seria = "Seria3", Data = new double[]{ 12, 14}}
};
//ôèëüòðàöèÿ ôàéëîâ äëÿ äèàëîãîâîãî îêíà
using var dialog = new SaveFileDialog
{
Filter = "docx|*.docx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
DiagramWord diagramWord = new(dialog.FileName, "Çàäàíèå 3", "Íàçâàíèå äèàãðàììû", LegendPosition.Right, diagramData, categories);
componentWord31.CreateLineChart(diagramWord);
MessageBox.Show("Äèàãðàììà ñîçäàíà óñïåøíî", "Ðåçóëüòàò", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void button3_Click(object sender, EventArgs e)
{
List<int[]> mergedColumns = new()
{
new int[] { 0, 1 } // Ïðèìåð îáúåäèíåíèÿ ñòîëáöîâ 0 è 1
};
List<ColumnDefinition> columnDefinitions = new List<ColumnDefinition>
{
new ColumnDefinition { Header = "Ëè÷íûå äàííûå", PropertyName = "PersonalData", Width = 11 },
new ColumnDefinition { Header = "", PropertyName = "PersonalData1", Width = 70 },
new ColumnDefinition { Header = "Group", PropertyName = "Group", Width = 21 }
};
List<ColumnDefinition> columnDefinitions2 = new List<ColumnDefinition>
{
new ColumnDefinition { Header = "FIO", PropertyName = "FIO", Width = 11 },
new ColumnDefinition { Header = "Email", PropertyName = "Email", Width = 70 },
new ColumnDefinition { Header = "Group", PropertyName = "Group", Width = 21 }
};
List<Student> data = new List<Student>
{
new Student { FIO = "John", Group = "Group1", Email = "email1@email" },
new Student { FIO = "Jane", Group = "Group2", Email = "email2@email" },
new Student { FIO = "Mike", Group = "Group3", Email = "email3@email" }
};
//ôèëüòðàöèÿ ôàéëîâ äëÿ äèàëîãîâîãî îêíà
using var dialog = new SaveFileDialog
{
Filter = "docx|*.docx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
TableWord<Student> tableWord = new(dialog.FileName, "Çàäàíèå 2", columnDefinitions, columnDefinitions2, data, mergedColumns);
componentWord21.CreateTable(tableWord);
MessageBox.Show("Ôàéë ñîçäàí", "Ðåçóëüòàò", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}

View File

@ -57,4 +57,13 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="componentWord11.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="componentWord31.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>203, 17</value>
</metadata>
<metadata name="componentWord21.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>389, 17</value>
</metadata>
</root>