From a71399d55b81f47e4e31602fd606bfcdeec4d464 Mon Sep 17 00:00:00 2001 From: Arkadiy Radaev Date: Mon, 28 Oct 2024 19:28:12 +0400 Subject: [PATCH] lab 2 res --- Library15/CopLibrary15.sln | 31 ++ Library15/Form1/Form1.Designer.cs | 338 ++++++++++++++++++ Library15/Form1/Form1.cs | 201 +++++++++++ Library15/Form1/Form1.csproj | 22 ++ Library15/Form1/Form1.resx | 132 +++++++ Library15/Form1/PersonWordTable.cs | 25 ++ Library15/Form1/Program.cs | 17 + Library15/Form1/TestPerson.cs | 27 ++ Library15/Library15/Class1.cs | 6 + Library15/Library15/ColumnInfo.cs | 23 ++ .../Exceptions/EmptyValueException.cs | 9 + .../Library15/Exceptions/NotFloatException.cs | 9 + .../Library15/InputComponent.Designer.cs | 83 +++++ Library15/Library15/InputComponent.cs | 75 ++++ Library15/Library15/InputComponent.resx | 120 +++++++ Library15/Library15/Library15.csproj | 22 ++ .../Library15/ListOutputComponent.Designer.cs | 64 ++++ Library15/Library15/ListOutputComponent.cs | 86 +++++ Library15/Library15/ListOutputComponent.resx | 120 +++++++ .../HelperEnum/WordDiagramLegendLocation.cs | 16 + .../HelperEnum/WordJustificationType.cs | 14 + .../HelperModels/WordDiagramInfo.cs | 26 ++ .../HelperModels/WordDiagramSeries.cs | 14 + .../OfficePackage/HelperModels/WordInfo.cs | 14 + .../HelperModels/WordParagraph.cs | 13 + .../OfficePackage/HelperModels/WordTable.cs | 15 + .../HelperModels/WordTableWithData.cs | 22 ++ .../HelperModels/WordTableWithHeader.cs | 18 + .../HelperModels/WordTextProperties.cs | 11 + .../OfficePackage/Implement/SaveToWord.cs | 220 ++++++++++++ .../Library15/SelectedComponent.Designer.cs | 60 ++++ Library15/Library15/SelectedComponent.cs | 45 +++ Library15/Library15/SelectedComponent.resx | 120 +++++++ Library15/Library15/Testing.Designer.cs | 73 ++++ Library15/Library15/Testing.cs | 68 ++++ Library15/Library15/Testing.resx | 120 +++++++ Library15/Library15/WordDiagram.Designer.cs | 36 ++ Library15/Library15/WordDiagram.cs | 34 ++ .../Library15/WordDocumentContext.Designer.cs | 36 ++ Library15/Library15/WordDocumentContext.cs | 52 +++ .../Library15/WordDocumentTable.Designer.cs | 36 ++ Library15/Library15/WordDocumentTable.cs | 200 +++++++++++ README.md | 2 +- 43 files changed, 2674 insertions(+), 1 deletion(-) create mode 100644 Library15/CopLibrary15.sln create mode 100644 Library15/Form1/Form1.Designer.cs create mode 100644 Library15/Form1/Form1.cs create mode 100644 Library15/Form1/Form1.csproj create mode 100644 Library15/Form1/Form1.resx create mode 100644 Library15/Form1/PersonWordTable.cs create mode 100644 Library15/Form1/Program.cs create mode 100644 Library15/Form1/TestPerson.cs create mode 100644 Library15/Library15/Class1.cs create mode 100644 Library15/Library15/ColumnInfo.cs create mode 100644 Library15/Library15/Exceptions/EmptyValueException.cs create mode 100644 Library15/Library15/Exceptions/NotFloatException.cs create mode 100644 Library15/Library15/InputComponent.Designer.cs create mode 100644 Library15/Library15/InputComponent.cs create mode 100644 Library15/Library15/InputComponent.resx create mode 100644 Library15/Library15/Library15.csproj create mode 100644 Library15/Library15/ListOutputComponent.Designer.cs create mode 100644 Library15/Library15/ListOutputComponent.cs create mode 100644 Library15/Library15/ListOutputComponent.resx create mode 100644 Library15/Library15/OfficePackage/HelperEnum/WordDiagramLegendLocation.cs create mode 100644 Library15/Library15/OfficePackage/HelperEnum/WordJustificationType.cs create mode 100644 Library15/Library15/OfficePackage/HelperModels/WordDiagramInfo.cs create mode 100644 Library15/Library15/OfficePackage/HelperModels/WordDiagramSeries.cs create mode 100644 Library15/Library15/OfficePackage/HelperModels/WordInfo.cs create mode 100644 Library15/Library15/OfficePackage/HelperModels/WordParagraph.cs create mode 100644 Library15/Library15/OfficePackage/HelperModels/WordTable.cs create mode 100644 Library15/Library15/OfficePackage/HelperModels/WordTableWithData.cs create mode 100644 Library15/Library15/OfficePackage/HelperModels/WordTableWithHeader.cs create mode 100644 Library15/Library15/OfficePackage/HelperModels/WordTextProperties.cs create mode 100644 Library15/Library15/OfficePackage/Implement/SaveToWord.cs create mode 100644 Library15/Library15/SelectedComponent.Designer.cs create mode 100644 Library15/Library15/SelectedComponent.cs create mode 100644 Library15/Library15/SelectedComponent.resx create mode 100644 Library15/Library15/Testing.Designer.cs create mode 100644 Library15/Library15/Testing.cs create mode 100644 Library15/Library15/Testing.resx create mode 100644 Library15/Library15/WordDiagram.Designer.cs create mode 100644 Library15/Library15/WordDiagram.cs create mode 100644 Library15/Library15/WordDocumentContext.Designer.cs create mode 100644 Library15/Library15/WordDocumentContext.cs create mode 100644 Library15/Library15/WordDocumentTable.Designer.cs create mode 100644 Library15/Library15/WordDocumentTable.cs diff --git a/Library15/CopLibrary15.sln b/Library15/CopLibrary15.sln new file mode 100644 index 0000000..d6f6b67 --- /dev/null +++ b/Library15/CopLibrary15.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34221.43 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Form1", "Form1\Form1.csproj", "{9A55F075-005A-433D-B6CC-89E850999353}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library15", "Library15\Library15.csproj", "{BDB71E57-5F32-48F9-A28C-B42A3848DA07}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9A55F075-005A-433D-B6CC-89E850999353}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9A55F075-005A-433D-B6CC-89E850999353}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9A55F075-005A-433D-B6CC-89E850999353}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9A55F075-005A-433D-B6CC-89E850999353}.Release|Any CPU.Build.0 = Release|Any CPU + {BDB71E57-5F32-48F9-A28C-B42A3848DA07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BDB71E57-5F32-48F9-A28C-B42A3848DA07}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BDB71E57-5F32-48F9-A28C-B42A3848DA07}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BDB71E57-5F32-48F9-A28C-B42A3848DA07}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {5A6AC5CC-7959-44F7-8CAC-06D9B6C31516} + EndGlobalSection +EndGlobal diff --git a/Library15/Form1/Form1.Designer.cs b/Library15/Form1/Form1.Designer.cs new file mode 100644 index 0000000..adb332e --- /dev/null +++ b/Library15/Form1/Form1.Designer.cs @@ -0,0 +1,338 @@ +namespace Form1 +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + public void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + selectComponent = new Library15.SelectedComponent(); + groupBoxSelect = new GroupBox(); + buttonGetSelected = new Button(); + buttonClear = new Button(); + textBox = new TextBox(); + buttonAdd = new Button(); + groupBoxInput = new GroupBox(); + inputComponent = new Library15.InputComponent(); + buttonShowFloat = new Button(); + groupBoxListOutput = new GroupBox(); + buttonGetListOutput = new Button(); + buttonAddListOutput = new Button(); + buttonClearListOutput = new Button(); + listOutputComponent = new Library15.ListOutputComponent(); + wordDocumentContext1 = new Library15.WordDocumentContext(components); + groupBoxSimpelTable = new GroupBox(); + buttonSimpleTable = new Button(); + groupBoxDiagram = new GroupBox(); + buttonCreateDiagram = new Button(); + wordDiagram = new Library15.WordDiagram(components); + groupBoxTableWithHeaders = new GroupBox(); + buttonWordTableWithHeaders = new Button(); + wordDocumentTable1 = new Library15.WordDocumentTable(components); + groupBoxSelect.SuspendLayout(); + groupBoxInput.SuspendLayout(); + groupBoxListOutput.SuspendLayout(); + groupBoxSimpelTable.SuspendLayout(); + groupBoxDiagram.SuspendLayout(); + groupBoxTableWithHeaders.SuspendLayout(); + SuspendLayout(); + // + // selectComponent + // + selectComponent.Location = new Point(8, 40); + selectComponent.Margin = new Padding(5); + selectComponent.Name = "selectComponent"; + selectComponent.SelectedItem = ""; + selectComponent.Size = new Size(205, 282); + selectComponent.TabIndex = 0; + // + // groupBoxSelect + // + groupBoxSelect.Controls.Add(buttonGetSelected); + groupBoxSelect.Controls.Add(buttonClear); + groupBoxSelect.Controls.Add(textBox); + groupBoxSelect.Controls.Add(buttonAdd); + groupBoxSelect.Controls.Add(selectComponent); + groupBoxSelect.Location = new Point(15, 1); + groupBoxSelect.Margin = new Padding(4); + groupBoxSelect.Name = "groupBoxSelect"; + groupBoxSelect.Padding = new Padding(4); + groupBoxSelect.Size = new Size(378, 273); + groupBoxSelect.TabIndex = 1; + groupBoxSelect.TabStop = false; + groupBoxSelect.Text = "Лаб1.1"; + // + // buttonGetSelected + // + buttonGetSelected.Location = new Point(214, 219); + buttonGetSelected.Margin = new Padding(4); + buttonGetSelected.Name = "buttonGetSelected"; + buttonGetSelected.Size = new Size(156, 36); + buttonGetSelected.TabIndex = 4; + buttonGetSelected.Text = "Выбрать"; + buttonGetSelected.UseVisualStyleBackColor = true; + buttonGetSelected.Click += SelectComponent_ItemSelected; + // + // buttonClear + // + buttonClear.Location = new Point(214, 165); + buttonClear.Margin = new Padding(4); + buttonClear.Name = "buttonClear"; + buttonClear.Size = new Size(156, 36); + buttonClear.TabIndex = 3; + buttonClear.Text = "Очистить"; + buttonClear.UseVisualStyleBackColor = true; + buttonClear.Click += buttonClearList_Click; + // + // textBox + // + textBox.Location = new Point(214, 51); + textBox.Margin = new Padding(4); + textBox.Name = "textBox"; + textBox.Size = new Size(155, 31); + textBox.TabIndex = 2; + // + // buttonAdd + // + buttonAdd.Location = new Point(214, 115); + buttonAdd.Margin = new Padding(4); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(156, 36); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // groupBoxInput + // + groupBoxInput.Controls.Add(inputComponent); + groupBoxInput.Controls.Add(buttonShowFloat); + groupBoxInput.Location = new Point(450, 1); + groupBoxInput.Margin = new Padding(4); + groupBoxInput.Name = "groupBoxInput"; + groupBoxInput.Padding = new Padding(4); + groupBoxInput.Size = new Size(238, 201); + groupBoxInput.TabIndex = 3; + groupBoxInput.TabStop = false; + groupBoxInput.Text = "Лаб1.2"; + // + // inputComponent + // + inputComponent.Location = new Point(8, 25); + inputComponent.Margin = new Padding(4); + inputComponent.Name = "inputComponent"; + inputComponent.Size = new Size(222, 115); + inputComponent.TabIndex = 5; + // + // buttonShowFloat + // + buttonShowFloat.Location = new Point(100, 148); + buttonShowFloat.Margin = new Padding(4); + buttonShowFloat.Name = "buttonShowFloat"; + buttonShowFloat.Size = new Size(118, 36); + buttonShowFloat.TabIndex = 4; + buttonShowFloat.Text = "Показать"; + buttonShowFloat.UseVisualStyleBackColor = true; + buttonShowFloat.Click += buttonShowFloat_Click; + // + // groupBoxListOutput + // + groupBoxListOutput.Controls.Add(buttonGetListOutput); + groupBoxListOutput.Controls.Add(buttonAddListOutput); + groupBoxListOutput.Controls.Add(buttonClearListOutput); + groupBoxListOutput.Controls.Add(listOutputComponent); + groupBoxListOutput.Location = new Point(15, 302); + groupBoxListOutput.Margin = new Padding(4); + groupBoxListOutput.Name = "groupBoxListOutput"; + groupBoxListOutput.Padding = new Padding(4); + groupBoxListOutput.Size = new Size(712, 301); + groupBoxListOutput.TabIndex = 4; + groupBoxListOutput.TabStop = false; + groupBoxListOutput.Text = "Лаб1.3"; + // + // buttonGetListOutput + // + buttonGetListOutput.Location = new Point(571, 179); + buttonGetListOutput.Margin = new Padding(4); + buttonGetListOutput.Name = "buttonGetListOutput"; + buttonGetListOutput.Size = new Size(118, 36); + buttonGetListOutput.TabIndex = 7; + buttonGetListOutput.Text = "Выбрать"; + buttonGetListOutput.UseVisualStyleBackColor = true; + buttonGetListOutput.Click += buttonGetListOutput_Click; + // + // buttonAddListOutput + // + buttonAddListOutput.Location = new Point(571, 32); + buttonAddListOutput.Margin = new Padding(4); + buttonAddListOutput.Name = "buttonAddListOutput"; + buttonAddListOutput.Size = new Size(118, 36); + buttonAddListOutput.TabIndex = 6; + buttonAddListOutput.Text = "Добавить"; + buttonAddListOutput.UseVisualStyleBackColor = true; + buttonAddListOutput.Click += buttonAddListOutput_Click; + // + // buttonClearListOutput + // + buttonClearListOutput.Location = new Point(571, 101); + buttonClearListOutput.Margin = new Padding(4); + buttonClearListOutput.Name = "buttonClearListOutput"; + buttonClearListOutput.Size = new Size(118, 36); + buttonClearListOutput.TabIndex = 5; + buttonClearListOutput.Text = "Очистить"; + buttonClearListOutput.UseVisualStyleBackColor = true; + buttonClearListOutput.Click += buttonClearListOutput_Click; + // + // listOutputComponent + // + listOutputComponent.BackColor = SystemColors.ButtonHighlight; + listOutputComponent.Location = new Point(8, 32); + listOutputComponent.Margin = new Padding(5); + listOutputComponent.Name = "listOutputComponent"; + listOutputComponent.SelectedRow = -1; + listOutputComponent.Size = new Size(556, 261); + listOutputComponent.TabIndex = 0; + // + // groupBoxSimpelTable + // + groupBoxSimpelTable.Controls.Add(buttonSimpleTable); + groupBoxSimpelTable.Location = new Point(1133, 26); + groupBoxSimpelTable.Margin = new Padding(4); + groupBoxSimpelTable.Name = "groupBoxSimpelTable"; + groupBoxSimpelTable.Padding = new Padding(4); + groupBoxSimpelTable.Size = new Size(190, 126); + groupBoxSimpelTable.TabIndex = 5; + groupBoxSimpelTable.TabStop = false; + groupBoxSimpelTable.Text = "Задание1"; + // + // buttonSimpleTable + // + buttonSimpleTable.Location = new Point(8, 50); + buttonSimpleTable.Margin = new Padding(4); + buttonSimpleTable.Name = "buttonSimpleTable"; + buttonSimpleTable.Size = new Size(172, 36); + buttonSimpleTable.TabIndex = 6; + buttonSimpleTable.Text = "Таблицы Word "; + buttonSimpleTable.UseVisualStyleBackColor = true; + buttonSimpleTable.Click += buttonSimpleTable_Click; + // + // groupBoxDiagram + // + groupBoxDiagram.Controls.Add(buttonCreateDiagram); + groupBoxDiagram.Location = new Point(1122, 334); + groupBoxDiagram.Margin = new Padding(4); + groupBoxDiagram.Name = "groupBoxDiagram"; + groupBoxDiagram.Padding = new Padding(4); + groupBoxDiagram.Size = new Size(226, 126); + groupBoxDiagram.TabIndex = 6; + groupBoxDiagram.TabStop = false; + groupBoxDiagram.Text = "Задание3"; + // + // buttonCreateDiagram + // + buttonCreateDiagram.Location = new Point(29, 50); + buttonCreateDiagram.Margin = new Padding(4); + buttonCreateDiagram.Name = "buttonCreateDiagram"; + buttonCreateDiagram.Size = new Size(159, 36); + buttonCreateDiagram.TabIndex = 0; + buttonCreateDiagram.Text = "Создать Word"; + buttonCreateDiagram.UseVisualStyleBackColor = true; + buttonCreateDiagram.Click += createDiagram_Click; + // + // groupBoxTableWithHeaders + // + groupBoxTableWithHeaders.Controls.Add(buttonWordTableWithHeaders); + groupBoxTableWithHeaders.Location = new Point(1133, 178); + groupBoxTableWithHeaders.Margin = new Padding(4); + groupBoxTableWithHeaders.Name = "groupBoxTableWithHeaders"; + groupBoxTableWithHeaders.Padding = new Padding(4); + groupBoxTableWithHeaders.Size = new Size(199, 126); + groupBoxTableWithHeaders.TabIndex = 7; + groupBoxTableWithHeaders.TabStop = false; + groupBoxTableWithHeaders.Text = "Задание2"; + // + // buttonWordTableWithHeaders + // + buttonWordTableWithHeaders.Location = new Point(8, 50); + buttonWordTableWithHeaders.Margin = new Padding(4); + buttonWordTableWithHeaders.Name = "buttonWordTableWithHeaders"; + buttonWordTableWithHeaders.Size = new Size(165, 36); + buttonWordTableWithHeaders.TabIndex = 0; + buttonWordTableWithHeaders.Text = "Таблица Word "; + buttonWordTableWithHeaders.UseVisualStyleBackColor = true; + buttonWordTableWithHeaders.Click += WordSaveHeaders_Click; + // + // Form1 + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1468, 650); + Controls.Add(groupBoxTableWithHeaders); + Controls.Add(groupBoxDiagram); + Controls.Add(groupBoxSimpelTable); + Controls.Add(groupBoxListOutput); + Controls.Add(groupBoxInput); + Controls.Add(groupBoxSelect); + Margin = new Padding(4); + Name = "Form1"; + Text = "i love COP"; + groupBoxSelect.ResumeLayout(false); + groupBoxSelect.PerformLayout(); + groupBoxInput.ResumeLayout(false); + groupBoxListOutput.ResumeLayout(false); + groupBoxSimpelTable.ResumeLayout(false); + groupBoxDiagram.ResumeLayout(false); + groupBoxTableWithHeaders.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private Library15.SelectedComponent selectComponent; + private GroupBox groupBoxSelect; + private Button buttonGetSelected; + private Button buttonClear; + private TextBox textBox; + private Button buttonAdd; + private GroupBox groupBoxInput; + private Button buttonShowFloat; + private GroupBox groupBoxListOutput; + private Library15.ListOutputComponent listOutputComponent; + private Button buttonGetListOutput; + private Button buttonAddListOutput; + private Button buttonClearListOutput; + private Library15.WordDocumentContext wordDocumentContext1; + private GroupBox groupBoxSimpelTable; + private Button buttonSimpleTable; + private GroupBox groupBoxDiagram; + private Button buttonCreateDiagram; + private Library15.WordDiagram wordDiagram; + private GroupBox groupBoxTableWithHeaders; + private Button buttonWordTableWithHeaders; + private Library15.WordDocumentTable wordDocumentTable1; + private Library15.InputComponent inputComponent; + } +} \ No newline at end of file diff --git a/Library15/Form1/Form1.cs b/Library15/Form1/Form1.cs new file mode 100644 index 0000000..3c3e74a --- /dev/null +++ b/Library15/Form1/Form1.cs @@ -0,0 +1,201 @@ +using DocumentFormat.OpenXml.Office2013.Excel; +using DocumentFormat.OpenXml.Spreadsheet; +using Microsoft.VisualBasic.Devices; +using System.Windows.Forms; +using Library15; +using Library15.Exceptions; +using Library15.OfficePackage.HelperModels; + +namespace Form1 +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + + + InitializeSelectComponent(); + InitializeInputComponent(); + + } + private void InitializeSelectComponent() + { + selectComponent.Input(""); + selectComponent.Input(""); + selectComponent.Input(""); + selectComponent.Input(""); + } + private void SelectComponent_ItemSelected(object sender, EventArgs e) + { + MessageBox.Show(selectComponent.SelectedItem); + } + private void buttonAdd_Click(object sender, EventArgs e) + { + if (textBox.Text != "") + selectComponent.Input(textBox.Text); + } + private void buttonClearList_Click(object sender, EventArgs e) + { + selectComponent.ClearList(); + } + private void InitializeInputComponent() + { + inputComponent.FloatValue = 12.3f; + } + private void buttonShowFloat_Click(object sender, EventArgs e) + { + try + { + float? Value = inputComponent.FloatValue; + if (Value != null) + { + MessageBox.Show($" : {Value}"); + } + else + { + MessageBox.Show(" - null"); + } + } + catch (NotFloatException ex) + { + MessageBox.Show(ex.Message); + } + catch (EmptyValueException ex) + { + MessageBox.Show(ex.Message); + } + } + private void InitializeDataGridViewComponent() + { + listOutputComponent.ConfigColumn(new() + { + new ColumnInfo("", 0, false, "Id"), + new ColumnInfo("", 150, true, "Name"), + new ColumnInfo("", 100, true, "Surname"), + new ColumnInfo("", 100, true, "Age"), + }); + List Persons = new() + { + new TestPerson(1, "", "", 21), + new TestPerson(2, "", "", 33), + new TestPerson(3, "", "", 49), + }; + + foreach (TestPerson person in Persons) + { + listOutputComponent.AddItem(person); + } + } + + private void buttonAddListOutput_Click(object sender, EventArgs e) + { + InitializeDataGridViewComponent(); + } + + private void buttonClearListOutput_Click(object sender, EventArgs e) + { + listOutputComponent.ClearDataGridView(); + } + + private void buttonGetListOutput_Click(object sender, EventArgs e) + { + var Test = listOutputComponent.GetSelectedObject(); + MessageBox.Show(Test.ToString()); + } + #region + private void buttonSimpleTable_Click(object sender, EventArgs e) + { + List data = new List + { + new string[,] + { + { " 1 1", " 1 2", " 1 3" }, + { " 2 1", " 2 2", " 2 3" }, + { " 3 1", " 3 2", " 3 3" }, + }, + new string[,] + { + { " 1 1", " 1 2", " 1 3", " 1 4", " 1 5" }, + { " 2 1", " 2 2", " 2 3", " 2 4", " 2 5" }, + { " 3 1", " 3 2", " 3 3", " 3 4", " 3 5" }, + { " 4 1", " 4 2", " 4 3", " 4 4", " 4 5" }, + } + }; + var info = new WordTable + { + FileName = "C://Study/ULSTU/3_kurs/COP21.docx", + Title = " ", + Table = data, + }; + wordDocumentContext1.CreateWord(info); + MessageBox.Show("Word !", "", MessageBoxButtons.OK, MessageBoxIcon.Information); + + } + #endregion + + #region + + readonly List PersonsWord = new() + { + new PersonWordTable("", "", "", 22, 120.12), + new PersonWordTable("", "", "", 20, 300.83), + new PersonWordTable("", "", "", 59, 601.3), + }; + private void WordSaveHeaders_Click(object sender, EventArgs e) + { + wordDocumentTable1.CreateTable(new WordTableWithData + { + FileName = "C://Study/ULSTU/3_kurs/COP22.docx", + Title = " ", + ColumnsRowsWidth = new List<(int Column, int Row)> { (5, 5), (10, 5), (10, 0), (5, 0), (10,5) }, + Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)> + { + (0, 0, "", "Id"), + (1, 0, "", "Surname"), + (2, 0, "", "Name"), + (3, 0, "", "Age"), + (4, 0, "IQ", "Premia"), + }, + Data = PersonsWord, + NullReplace = "null" + }); + MessageBox.Show("Word !", ""); + } + + #endregion + + #region + private void createDiagram_Click(object sender, EventArgs e) + { + try + { + wordDiagram.CreateDiagram( + new WordDiagramInfo + { + FileName = "C://Study/ULSTU/3_kurs/COP23.docx", + Title = " ", + ChartTitle = "", + LegendLocation = Library15.OfficePackage.HelperEnum.WordDiagramLegendLocation.Top, + Series = new WordDiagramSeries + { + SeriesName = "", + Data = new Dictionary + { + { "Gelly", 21 }, + { "lada", 45.5 }, + { "Ford", 12.5 }, + { "Coca-cola", 7.5 }, + } + } + }); + MessageBox.Show("Word !", ""); + } + catch (Exception ex) + { + MessageBox.Show($": {ex.Message}"); + } + } + #endregion + } +} \ No newline at end of file diff --git a/Library15/Form1/Form1.csproj b/Library15/Form1/Form1.csproj new file mode 100644 index 0000000..5e9d0d5 --- /dev/null +++ b/Library15/Form1/Form1.csproj @@ -0,0 +1,22 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Library15/Form1/Form1.resx b/Library15/Form1/Form1.resx new file mode 100644 index 0000000..e60db7f --- /dev/null +++ b/Library15/Form1/Form1.resx @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 165, 17 + + + 17, 17 + + + 383, 17 + + + 61 + + \ No newline at end of file diff --git a/Library15/Form1/PersonWordTable.cs b/Library15/Form1/PersonWordTable.cs new file mode 100644 index 0000000..233c75b --- /dev/null +++ b/Library15/Form1/PersonWordTable.cs @@ -0,0 +1,25 @@ +namespace Library15 +{ + public class PersonWordTable + { + public string Id { get; set; } + + public string Name { get; set; } = string.Empty; + + public string Surname { get; set; } = string.Empty; + + public int Age { get; set; } + public double Premia { get; set; } + public PersonWordTable() + { } + + public PersonWordTable(string Id, string Name, string Surname, int Age, double Premia) + { + this.Id = Id; + this.Name = Name; + this.Surname = Surname; + this.Age = Age; + this.Premia = Premia; + } + } +} diff --git a/Library15/Form1/Program.cs b/Library15/Form1/Program.cs new file mode 100644 index 0000000..b430c88 --- /dev/null +++ b/Library15/Form1/Program.cs @@ -0,0 +1,17 @@ +namespace Form1 +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [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 Form1()); + } + } +} \ No newline at end of file diff --git a/Library15/Form1/TestPerson.cs b/Library15/Form1/TestPerson.cs new file mode 100644 index 0000000..f82b4e3 --- /dev/null +++ b/Library15/Form1/TestPerson.cs @@ -0,0 +1,27 @@ +namespace Library15 +{ + public class TestPerson + { + public int Id { get; set; } + + public string Name { get; set; } = string.Empty; + + public string Surname { get; set; } = string.Empty; + + public int Age { get; set; } + public TestPerson() + { } + + public TestPerson(int Id, string Name, string Surname, int Age) + { + this.Id = Id; + this.Name = Name; + this.Surname = Surname; + this.Age = Age; + } + public string ToString() + { + return $"{Id}. {Name} {Surname} Возраст: {Age}"; + } + } +} diff --git a/Library15/Library15/Class1.cs b/Library15/Library15/Class1.cs new file mode 100644 index 0000000..3840a60 --- /dev/null +++ b/Library15/Library15/Class1.cs @@ -0,0 +1,6 @@ +namespace Library15 +{ + public class Class1 + { + } +} \ No newline at end of file diff --git a/Library15/Library15/ColumnInfo.cs b/Library15/Library15/ColumnInfo.cs new file mode 100644 index 0000000..332c1e9 --- /dev/null +++ b/Library15/Library15/ColumnInfo.cs @@ -0,0 +1,23 @@ +namespace Library15 +{ + public class ColumnInfo + { + public int ColumnsCount { get; set; } + + public string Header { get; set; } + + public int Width { get; set; } + + public bool IsVisible { get; set; } + + public string PropertiesName { get; set; } + + public ColumnInfo(string Header, int Width, bool IsVisible, string PropertiesName) + { + this.Header = Header; + this.Width = Width; + this.IsVisible = IsVisible; + this.PropertiesName = PropertiesName; + } + } +} diff --git a/Library15/Library15/Exceptions/EmptyValueException.cs b/Library15/Library15/Exceptions/EmptyValueException.cs new file mode 100644 index 0000000..3134e27 --- /dev/null +++ b/Library15/Library15/Exceptions/EmptyValueException.cs @@ -0,0 +1,9 @@ +namespace Library15.Exceptions +{ + public class EmptyValueException : ApplicationException + { + public EmptyValueException() + : base("Значение не введено") + { } + } +} diff --git a/Library15/Library15/Exceptions/NotFloatException.cs b/Library15/Library15/Exceptions/NotFloatException.cs new file mode 100644 index 0000000..8ad4af6 --- /dev/null +++ b/Library15/Library15/Exceptions/NotFloatException.cs @@ -0,0 +1,9 @@ +namespace Library15.Exceptions +{ + public class NotFloatException : ApplicationException + { + public NotFloatException() + : base("Введенное значение не является вещественным") + { } + } +} diff --git a/Library15/Library15/InputComponent.Designer.cs b/Library15/Library15/InputComponent.Designer.cs new file mode 100644 index 0000000..c79937f --- /dev/null +++ b/Library15/Library15/InputComponent.Designer.cs @@ -0,0 +1,83 @@ +namespace Library15 +{ + partial class InputComponent + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + public void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + IsNullCheckBox = new CheckBox(); + textBoxInput = new TextBox(); + label1 = new Label(); + SuspendLayout(); + // + // IsNullCheckBox + // + IsNullCheckBox.AutoSize = true; + IsNullCheckBox.Location = new Point(46, 69); + IsNullCheckBox.Margin = new Padding(4, 4, 4, 4); + IsNullCheckBox.Name = "IsNullCheckBox"; + IsNullCheckBox.Size = new Size(22, 21); + IsNullCheckBox.TabIndex = 0; + IsNullCheckBox.UseVisualStyleBackColor = true; + // + // textBoxInput + // + textBoxInput.Location = new Point(46, 18); + textBoxInput.Margin = new Padding(4, 4, 4, 4); + textBoxInput.Name = "textBoxInput"; + textBoxInput.Size = new Size(155, 31); + textBoxInput.TabIndex = 1; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(75, 69); + label1.Name = "label1"; + label1.Size = new Size(48, 25); + label1.TabIndex = 2; + label1.Text = "null?"; + // + // InputComponent + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(label1); + Controls.Add(textBoxInput); + Controls.Add(IsNullCheckBox); + Margin = new Padding(4, 4, 4, 4); + Name = "InputComponent"; + Size = new Size(212, 112); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private CheckBox IsNullCheckBox; + private TextBox textBoxInput; + private Label label1; + } +} diff --git a/Library15/Library15/InputComponent.cs b/Library15/Library15/InputComponent.cs new file mode 100644 index 0000000..301e43a --- /dev/null +++ b/Library15/Library15/InputComponent.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Library15.Exceptions; + +namespace Library15 +{ + public partial class InputComponent : UserControl + { + private event EventHandler? _valueChanged; + public InputComponent() + { + InitializeComponent(); + } + public float? FloatValue + { + get + { + if (IsNullCheckBox.Checked) + { + return null; + } + + if (string.IsNullOrEmpty(textBoxInput.Text)) + { + throw new EmptyValueException(); + } + + float ParsedFloat; + if (float.TryParse(textBoxInput.Text, out ParsedFloat)) + { + return ParsedFloat; + } + else + { + throw new NotFloatException(); + } + } + set + { + SetNullState(value is null, true); + if (value is not null) + { + textBoxInput.Text = value.ToString(); + } + } + } + public event EventHandler? ValueChanged + { + add { _valueChanged += value; } + remove { _valueChanged -= value; } + } + private void SetNullState(bool IsNull = false, bool ClearText = false) + { + IsNullCheckBox.Checked = IsNull; + textBoxInput.Enabled = !IsNull; + + if (ClearText) + { + textBoxInput.Text = string.Empty; + } + } + + private void textBox_TextChanged(object sender, EventArgs e) + { + _valueChanged?.Invoke(this, e); + } + } +} diff --git a/Library15/Library15/InputComponent.resx b/Library15/Library15/InputComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Library15/Library15/InputComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Library15/Library15/Library15.csproj b/Library15/Library15/Library15.csproj new file mode 100644 index 0000000..77309af --- /dev/null +++ b/Library15/Library15/Library15.csproj @@ -0,0 +1,22 @@ + + + + net6.0-windows + enable + true + enable + True + $(VersionPrefix)1.0.2 + + + + + + + + + + + + + diff --git a/Library15/Library15/ListOutputComponent.Designer.cs b/Library15/Library15/ListOutputComponent.Designer.cs new file mode 100644 index 0000000..d1f9dca --- /dev/null +++ b/Library15/Library15/ListOutputComponent.Designer.cs @@ -0,0 +1,64 @@ +namespace Library15 +{ + partial class ListOutputComponent + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + public void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.BackgroundColor = SystemColors.ButtonHighlight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.Margin = new Padding(4, 4, 4, 4); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(750, 422); + dataGridView.TabIndex = 0; + // + // ListOutputComponent + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(dataGridView); + Margin = new Padding(4, 4, 4, 4); + Name = "ListOutputComponent"; + Size = new Size(750, 422); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + } +} diff --git a/Library15/Library15/ListOutputComponent.cs b/Library15/Library15/ListOutputComponent.cs new file mode 100644 index 0000000..98b2afc --- /dev/null +++ b/Library15/Library15/ListOutputComponent.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Library15 +{ + public partial class ListOutputComponent : UserControl + { + public ListOutputComponent() + { + InitializeComponent(); + } + public DataGridViewRowCollection Rows + { + get { return dataGridView.Rows; } + } + public int SelectedRow + { + get + { + return dataGridView.SelectedRows.Count == 1 ? dataGridView.SelectedRows[0].Index : -1; + } + set + { + if (value >= 0 && value < dataGridView.Rows.Count) + { + dataGridView.Rows[value].Selected = true; + } + } + } + public void ConfigColumn(List columns) + { + dataGridView.Columns.Clear(); + + dataGridView.ColumnCount = columns.Count; + + for (int i = 0; i < columns.Count; ++i) + { + dataGridView.Columns[i].HeaderText = columns[i].Header; + dataGridView.Columns[i].Width = columns[i].Width; + dataGridView.Columns[i].Visible = columns[i].IsVisible; + dataGridView.Columns[i].Name = columns[i].PropertiesName; + } + } + public void ClearDataGridView() + { + dataGridView.Rows.Clear(); + } + public T GetSelectedObject() where T : class, new() + { + T obj = new(); + var properties = typeof(T).GetProperties(); + + foreach (var property in properties) + { + var cellValue = dataGridView.Rows[SelectedRow].Cells[property.Name].Value; + if (cellValue != null) + { + property.SetValue(obj, Convert.ChangeType(cellValue, property.PropertyType)); + } + } + + return obj; + } + public void AddItem(T item) + { + if (item == null) + return; + + int rowIndex = dataGridView.Rows.Add(); + + foreach (DataGridViewColumn Column in dataGridView.Columns) + { + var Property = typeof(T).GetProperties().FirstOrDefault(x => x.Name == Column.Name); + var Value = Property.GetValue(item); + dataGridView.Rows[rowIndex].Cells[Column.Index].Value = Value; + } + } + } +} diff --git a/Library15/Library15/ListOutputComponent.resx b/Library15/Library15/ListOutputComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Library15/Library15/ListOutputComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Library15/Library15/OfficePackage/HelperEnum/WordDiagramLegendLocation.cs b/Library15/Library15/OfficePackage/HelperEnum/WordDiagramLegendLocation.cs new file mode 100644 index 0000000..2fa5c5d --- /dev/null +++ b/Library15/Library15/OfficePackage/HelperEnum/WordDiagramLegendLocation.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Library15.OfficePackage.HelperEnum +{ + public enum WordDiagramLegendLocation + { + Left, + Right, + Top, + Bottom, + } +} diff --git a/Library15/Library15/OfficePackage/HelperEnum/WordJustificationType.cs b/Library15/Library15/OfficePackage/HelperEnum/WordJustificationType.cs new file mode 100644 index 0000000..07f0489 --- /dev/null +++ b/Library15/Library15/OfficePackage/HelperEnum/WordJustificationType.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Library15.OfficePackage.HelperEnum +{ + public enum WordJustificationType + { + Center, + Both + } +} diff --git a/Library15/Library15/OfficePackage/HelperModels/WordDiagramInfo.cs b/Library15/Library15/OfficePackage/HelperModels/WordDiagramInfo.cs new file mode 100644 index 0000000..541030f --- /dev/null +++ b/Library15/Library15/OfficePackage/HelperModels/WordDiagramInfo.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Library15.OfficePackage.HelperEnum; + +namespace Library15.OfficePackage.HelperModels +{ + public class WordDiagramInfo : WordInfo + { + public string ChartTitle { get; set; } = string.Empty; + public WordDiagramLegendLocation LegendLocation { get; set; } = WordDiagramLegendLocation.Right; + public WordDiagramSeries Series { get; set; } = new(); + + public void CheckFields() + { + if (string.IsNullOrEmpty(FileName)) + throw new ArgumentNullException(nameof(FileName), "File path and name cannot be null or empty."); + if (string.IsNullOrEmpty(Title)) + throw new ArgumentNullException(nameof(Title), "Title cannot be null or empty."); + if (Series == null) + throw new ArgumentNullException(nameof(Series), "Data cannot be null or empty."); + } + } +} diff --git a/Library15/Library15/OfficePackage/HelperModels/WordDiagramSeries.cs b/Library15/Library15/OfficePackage/HelperModels/WordDiagramSeries.cs new file mode 100644 index 0000000..329c22d --- /dev/null +++ b/Library15/Library15/OfficePackage/HelperModels/WordDiagramSeries.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Library15.OfficePackage.HelperModels +{ + public class WordDiagramSeries + { + public string SeriesName { get; set; } = string.Empty; + public Dictionary Data = new(); + } +} diff --git a/Library15/Library15/OfficePackage/HelperModels/WordInfo.cs b/Library15/Library15/OfficePackage/HelperModels/WordInfo.cs new file mode 100644 index 0000000..f5df573 --- /dev/null +++ b/Library15/Library15/OfficePackage/HelperModels/WordInfo.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Library15.OfficePackage.HelperModels +{ + public class WordInfo + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + } +} diff --git a/Library15/Library15/OfficePackage/HelperModels/WordParagraph.cs b/Library15/Library15/OfficePackage/HelperModels/WordParagraph.cs new file mode 100644 index 0000000..e1e8e47 --- /dev/null +++ b/Library15/Library15/OfficePackage/HelperModels/WordParagraph.cs @@ -0,0 +1,13 @@ +using Library15.OfficePackage.HelperEnum; + +namespace Library15.OfficePackage.HelperModels +{ + public class WordParagraph + { + public List<(string, WordTextProperties)> Texts { get; set; } = new(); + public WordTextProperties? TextProperties { get; set; } + public string Text { get; set; } = string.Empty; + public string Style { get; set; } = string.Empty; + public WordJustificationType JustificationType { get; set; } + } +} diff --git a/Library15/Library15/OfficePackage/HelperModels/WordTable.cs b/Library15/Library15/OfficePackage/HelperModels/WordTable.cs new file mode 100644 index 0000000..8e08c76 --- /dev/null +++ b/Library15/Library15/OfficePackage/HelperModels/WordTable.cs @@ -0,0 +1,15 @@ +namespace Library15.OfficePackage.HelperModels +{ + public class WordTable : WordInfo + { + public List Table { get; set; } = new List(); + + public void CheckFields() + { + if (string.IsNullOrWhiteSpace(FileName) || string.IsNullOrWhiteSpace(Title) || Table == null || Table.Count == 0) + { + throw new ArgumentException("Все поля должны быть заполнены."); + } + } + } +} diff --git a/Library15/Library15/OfficePackage/HelperModels/WordTableWithData.cs b/Library15/Library15/OfficePackage/HelperModels/WordTableWithData.cs new file mode 100644 index 0000000..cae65dd --- /dev/null +++ b/Library15/Library15/OfficePackage/HelperModels/WordTableWithData.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Library15.OfficePackage.HelperModels +{ + public class WordTableWithData : WordTableWithHeader + { + public List Data { get; set; } + public void CheckFields() + { + if (Data == null || Data.Count == 0) + throw new ArgumentNullException("No data"); + if (ColumnsRowsWidth is null || ColumnsRowsWidth.Count == 0) + throw new ArgumentNullException("Rows width invalid"); + if (Headers is null || Headers.Count == 0) + throw new ArgumentNullException("Header data invalid"); + } + } +} diff --git a/Library15/Library15/OfficePackage/HelperModels/WordTableWithHeader.cs b/Library15/Library15/OfficePackage/HelperModels/WordTableWithHeader.cs new file mode 100644 index 0000000..f0c1f8f --- /dev/null +++ b/Library15/Library15/OfficePackage/HelperModels/WordTableWithHeader.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Library15.OfficePackage.HelperModels +{ + public class WordTableWithHeader : WordInfo + { + public (int Columns, int Rows) ColumnsRowsDataCount { get; set; } + public List<(int Column, int Row)>? ColumnsRowsWidth { get; init; } + public List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)>? Headers { get; init; } + public string NullReplace { get; set; } = "null"; + + + } +} diff --git a/Library15/Library15/OfficePackage/HelperModels/WordTextProperties.cs b/Library15/Library15/OfficePackage/HelperModels/WordTextProperties.cs new file mode 100644 index 0000000..281ce06 --- /dev/null +++ b/Library15/Library15/OfficePackage/HelperModels/WordTextProperties.cs @@ -0,0 +1,11 @@ +using Library15.OfficePackage.HelperEnum; + +namespace Library15.OfficePackage.HelperModels +{ + public class WordTextProperties + { + public string Size { get; set; } = string.Empty; + public bool Bold { get; set; } + public WordJustificationType JustificationType { get; set; } + } +} diff --git a/Library15/Library15/OfficePackage/Implement/SaveToWord.cs b/Library15/Library15/OfficePackage/Implement/SaveToWord.cs new file mode 100644 index 0000000..240b107 --- /dev/null +++ b/Library15/Library15/OfficePackage/Implement/SaveToWord.cs @@ -0,0 +1,220 @@ +using Library15.OfficePackage.HelperEnum; +using Library15.OfficePackage.HelperModels; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; +using Aspose.Words.Drawing.Charts; +using Aspose.Words; +using Aspose.Words.Drawing; +using Body = DocumentFormat.OpenXml.Wordprocessing.Body; +using Paragraph = DocumentFormat.OpenXml.Wordprocessing.Paragraph; +using Run = DocumentFormat.OpenXml.Wordprocessing.Run; +using Document = DocumentFormat.OpenXml.Wordprocessing.Document; + + +namespace Library15.OfficePackage.Implements +{ + public class SaveToWord + { + private Document _document; + private WordprocessingDocument? _wordDocument; + private Body? _docBody; + + private static JustificationValues GetJustificationValues(WordJustificationType type) + { + return type switch + { + WordJustificationType.Both => JustificationValues.Both, + WordJustificationType.Center => JustificationValues.Center, _ => JustificationValues.Left, + }; + } + + private static SectionProperties CreateSectionProperties() + { + var properties = new SectionProperties(); + var pageSize = new DocumentFormat.OpenXml.Wordprocessing.PageSize + { + Orient = PageOrientationValues.Portrait + }; + properties.AppendChild(pageSize); + return properties; + } + + private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties) + { + if (paragraphProperties == null) + { + return null; + } + var properties = new ParagraphProperties(); + properties.AppendChild(new Justification() + { + Val = GetJustificationValues(paragraphProperties.JustificationType) + }); + properties.AppendChild(new SpacingBetweenLines + { + LineRule = LineSpacingRuleValues.Auto + }); + properties.AppendChild(new Indentation()); + var paragraphMarkRunProperties = new ParagraphMarkRunProperties(); + if (!string.IsNullOrEmpty(paragraphProperties.Size)) + { + paragraphMarkRunProperties.AppendChild(new FontSize + { + Val = paragraphProperties.Size + }); + } + properties.AppendChild(paragraphMarkRunProperties); + return properties; + } + public void CreateWord(WordInfo info) + { + _wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document); + MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); + mainPart.Document = new Document(); + _docBody = mainPart.Document.AppendChild(new Body()); + } + public void CreateParagraph(WordParagraph paragraph) + { + if (_docBody == null || paragraph == null) + { + return; + } + var docParagraph = new Paragraph(); + + docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties)); + foreach (var run in paragraph.Texts) + { + var docRun = new Run(); + var properties = new RunProperties(); + properties.AppendChild(new FontSize { Val = run.Item2.Size }); + if (run.Item2.Bold) + { + properties.AppendChild(new Bold()); + } + docRun.AppendChild(properties); + docRun.AppendChild(new Text { Text = run.Item1, Space = SpaceProcessingModeValues.Preserve }); + docParagraph.AppendChild(docRun); + } + _docBody.AppendChild(docParagraph); + } + public void SaveWord(WordInfo info) + { + if (_docBody == null || _wordDocument == null) + { + return; + } + _docBody.AppendChild(CreateSectionProperties()); + _wordDocument.MainDocumentPart!.Document.Save(); + _wordDocument.Dispose(); + + } + public void CreateTable(string[,] table) + { + if (_docBody == null || table == null) + { + return; + } + Table docTable = new Table(); + TableProperties tableProps = new TableProperties( + new TableBorders( + new TopBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new BottomBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new LeftBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new RightBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideHorizontalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideVerticalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + } + )); + docTable.AppendChild(tableProps); + TableGrid tableGrid = new TableGrid(); + int height = table.GetLength(0); + int width = table.GetLength(1); + for (int i = 0; i < width; i++) + { + tableGrid.AppendChild(new GridColumn()); + } + TableRow tableRow = new TableRow(); + for (int i = 0; i < height; i++) + { + tableRow = new TableRow(); + for (int j = 0; j < width; j++) + { + var element = table[i,j]; + tableRow.AppendChild(CreateTableCell(element)); + } + docTable.AppendChild(tableRow); + } + _docBody.AppendChild(docTable); + } + private TableCell CreateTableCell(string element) + { + var tableParagraph = new Paragraph(); + var run = new Run(); + run.AppendChild(new Text { Text = element }); + tableParagraph.AppendChild(run); + var tableCell = new TableCell(); + tableCell.AppendChild(tableParagraph); + return tableCell; + } + + public void CreateDiagram(WordDiagramInfo parameters) + { + Aspose.Words.Document doc = new Aspose.Words.Document(); + DocumentBuilder builder = new DocumentBuilder(doc); + if (doc == null) + throw new ArgumentNullException(nameof(doc), "Document is not created."); + builder.ParagraphFormat.Style.Font.Size = 16; + builder.Writeln(parameters.Title); + Shape shape = builder.InsertChart(ChartType.Column, 432, 252); + Chart chart = shape.Chart; + GetLegendPosition(parameters, chart); + ChartSeriesCollection seriesColl = chart.Series; + seriesColl.Clear(); + ChartSeries series = chart.Series.Add(parameters.Series.SeriesName, parameters.Series.Data.Select(x => x.Key).ToArray(), parameters.Series.Data.Select(x => x.Value).ToArray()); + doc.Save(parameters.FileName); + } + + private void GetLegendPosition(WordDiagramInfo parameters, Chart chart) + { + switch (parameters.LegendLocation) + { + case WordDiagramLegendLocation.Left: + chart.Legend.Position = LegendPosition.Left; + break; + case WordDiagramLegendLocation.Right: + chart.Legend.Position = LegendPosition.Right; + break; + case WordDiagramLegendLocation.Top: + chart.Legend.Position = LegendPosition.Top; + break; + case WordDiagramLegendLocation.Bottom: + chart.Legend.Position = LegendPosition.Bottom; + break; + } + } + } +} diff --git a/Library15/Library15/SelectedComponent.Designer.cs b/Library15/Library15/SelectedComponent.Designer.cs new file mode 100644 index 0000000..64e2b6d --- /dev/null +++ b/Library15/Library15/SelectedComponent.Designer.cs @@ -0,0 +1,60 @@ +namespace Library15 +{ + partial class SelectedComponent + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + public void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + listBox = new ListBox(); + SuspendLayout(); + // + // listBox + // + listBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + listBox.FormattingEnabled = true; + listBox.ItemHeight = 25; + listBox.Location = new Point(4, 4); + listBox.Margin = new Padding(4, 4, 4, 4); + listBox.Name = "listBox"; + listBox.Size = new Size(155, 179); + listBox.TabIndex = 0; + // + // SelectedComponent + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(listBox); + Margin = new Padding(4, 4, 4, 4); + Name = "SelectedComponent"; + Size = new Size(164, 226); + ResumeLayout(false); + } + + #endregion + + private ListBox listBox; + } +} diff --git a/Library15/Library15/SelectedComponent.cs b/Library15/Library15/SelectedComponent.cs new file mode 100644 index 0000000..67ab830 --- /dev/null +++ b/Library15/Library15/SelectedComponent.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Library15 +{ + public partial class SelectedComponent : UserControl + { + private event EventHandler _itemSelected; + public SelectedComponent() + { + InitializeComponent(); + } + public void Input(string str) + { + if (string.IsNullOrEmpty(str)) + throw new ArgumentNullException("input"); + listBox.Items.Add(str); + } + public void ClearList() + { + listBox.Items.Clear(); + } + public string SelectedItem + { + get { return (string)listBox.SelectedItem ?? string.Empty; } + set { listBox.SelectedItem = value; } + } + public event EventHandler? ItemSelected + { + add { _itemSelected += value; } + remove { _itemSelected -= value; } + } + private void listBox_SelectedIndexChanged(object sender, EventArgs e) + { + _itemSelected?.Invoke(this, e); + } + } +} diff --git a/Library15/Library15/SelectedComponent.resx b/Library15/Library15/SelectedComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Library15/Library15/SelectedComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Library15/Library15/Testing.Designer.cs b/Library15/Library15/Testing.Designer.cs new file mode 100644 index 0000000..3e1f1bb --- /dev/null +++ b/Library15/Library15/Testing.Designer.cs @@ -0,0 +1,73 @@ +namespace Library15 +{ + partial class Testing + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + public void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + pictureBox = new PictureBox(); + button = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + SuspendLayout(); + // + // pictureBox + // + pictureBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + pictureBox.Location = new Point(3, 3); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(187, 150); + pictureBox.TabIndex = 0; + pictureBox.TabStop = false; + // + // button + // + button.Anchor = AnchorStyles.Bottom; + button.Location = new Point(49, 156); + button.Name = "button"; + button.Size = new Size(94, 29); + button.TabIndex = 1; + button.Text = "Загрузить"; + button.UseVisualStyleBackColor = true; + button.Click += button_Click; + // + // Testing + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(button); + Controls.Add(pictureBox); + Name = "Testing"; + Size = new Size(193, 188); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private PictureBox pictureBox; + private Button button; + } +} diff --git a/Library15/Library15/Testing.cs b/Library15/Library15/Testing.cs new file mode 100644 index 0000000..b3e7275 --- /dev/null +++ b/Library15/Library15/Testing.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Library15 +{ + public partial class Testing : UserControl + { + private event EventHandler? _avatarChanged; + private event Action? _errorOccured; + public string Error { get; private set; } + public Image Avatar + { + get + { + return pictureBox.Image; + } + set + { + pictureBox.Image = value; + } + } + public event EventHandler AvatarChanged + { + add { _avatarChanged += value; } + remove { _avatarChanged -= value; } + } + public event Action AnErrorOccurred + { + add { _errorOccured += value; } + remove { _errorOccured -= value; } + } + public Testing() + { + InitializeComponent(); + Error = string.Empty; + } + private void ButtonLoad_Click(object sender, EventArgs e) + { + var ofd = new OpenFileDialog(); + if (ofd.ShowDialog() == DialogResult.OK) + { + try + { + pictureBox.Image = + Image.FromFile(ofd.FileName); + _avatarChanged?.Invoke(this, e); + } + catch (Exception ex) + { + Error = ex.Message; + _errorOccured?.Invoke(); + } + } + } + + private void button_Click(object sender, EventArgs e) + { + + } + } +} diff --git a/Library15/Library15/Testing.resx b/Library15/Library15/Testing.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Library15/Library15/Testing.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Library15/Library15/WordDiagram.Designer.cs b/Library15/Library15/WordDiagram.Designer.cs new file mode 100644 index 0000000..b79dad5 --- /dev/null +++ b/Library15/Library15/WordDiagram.Designer.cs @@ -0,0 +1,36 @@ +namespace Library15 +{ + partial class WordDiagram + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} diff --git a/Library15/Library15/WordDiagram.cs b/Library15/Library15/WordDiagram.cs new file mode 100644 index 0000000..4459cc6 --- /dev/null +++ b/Library15/Library15/WordDiagram.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Library15.OfficePackage.HelperEnum; +using Library15.OfficePackage.HelperModels; +using Library15.OfficePackage.Implements; + +namespace Library15 +{ + public partial class WordDiagram : Component + { + SaveToWord SaveToWord = new SaveToWord(); + public WordDiagram() + { + InitializeComponent(); + } + + public WordDiagram(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + public void CreateDiagram(WordDiagramInfo info) + { + info.CheckFields(); + SaveToWord.CreateDiagram(info); + } + } +} diff --git a/Library15/Library15/WordDocumentContext.Designer.cs b/Library15/Library15/WordDocumentContext.Designer.cs new file mode 100644 index 0000000..e208323 --- /dev/null +++ b/Library15/Library15/WordDocumentContext.Designer.cs @@ -0,0 +1,36 @@ +namespace Library15 +{ + partial class WordDocumentContext + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + public void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} diff --git a/Library15/Library15/WordDocumentContext.cs b/Library15/Library15/WordDocumentContext.cs new file mode 100644 index 0000000..acdd0ec --- /dev/null +++ b/Library15/Library15/WordDocumentContext.cs @@ -0,0 +1,52 @@ +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Library15.OfficePackage.Implements; +using DocumentFormat.OpenXml.Wordprocessing; +using Library15.OfficePackage.HelperModels; +using Library15.OfficePackage.HelperEnum; + +namespace Library15 +{ + public partial class WordDocumentContext : Component + { + SaveToWord SaveToWord = new SaveToWord(); + public WordDocumentContext() + { + InitializeComponent(); + } + + public WordDocumentContext(IContainer container) + { + container.Add(this); + InitializeComponent(); + } + + public void CreateWord(WordTable info) + { + info.CheckFields(); + SaveToWord.CreateWord(info); + SaveToWord.CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Center + } + }); + foreach (var table in info.Table) + { + SaveToWord.CreateTable(table); + SaveToWord.CreateParagraph(new WordParagraph()); + } + SaveToWord.SaveWord(info); + } + } +} diff --git a/Library15/Library15/WordDocumentTable.Designer.cs b/Library15/Library15/WordDocumentTable.Designer.cs new file mode 100644 index 0000000..7bf95c6 --- /dev/null +++ b/Library15/Library15/WordDocumentTable.Designer.cs @@ -0,0 +1,36 @@ +namespace Library15 +{ + partial class WordDocumentTable + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} diff --git a/Library15/Library15/WordDocumentTable.cs b/Library15/Library15/WordDocumentTable.cs new file mode 100644 index 0000000..739e82f --- /dev/null +++ b/Library15/Library15/WordDocumentTable.cs @@ -0,0 +1,200 @@ +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.EMMA; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; +using Library15.OfficePackage.HelperEnum; +using Library15.OfficePackage.HelperModels; +using Library15.OfficePackage.Implements; + +namespace Library15 +{ + public partial class WordDocumentTable : Component + { + private Document _document = null; + + private Body _body = null; + + private DocumentFormat.OpenXml.Wordprocessing.Table _table = null; + + private Document Document + { + get + { + if (_document == null) + { + _document = new Document(); + } + + return _document; + } + } + + private Body Body + { + get + { + if (_body == null) + { + _body = Document.AppendChild(new Body()); + } + + return _body; + } + } + + private DocumentFormat.OpenXml.Wordprocessing.Table Table + { + get + { + if (_table == null) + { + _table = new DocumentFormat.OpenXml.Wordprocessing.Table(); + } + + return _table; + } + } + public WordDocumentTable() + { + InitializeComponent(); + } + + public WordDocumentTable(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + + public void CreateTable(WordTableWithData config) + { + config.CheckFields(); + config.ColumnsRowsDataCount = (config.Data.Count + 2, config.ColumnsRowsWidth.Count); + CreateHeader(config.Title); + CreateTableWithHeader(); + CreateMultiHeader(config); + var array = new string[config.Data.Count, config.Headers.Count]; + for (var j = 0; j < config.Data.Count; j++) + { + for (var i = 0; i < config.Headers.Count; i++) + { + (int, int, string, string) first = (0, 0, null, null)!; + foreach (var x in config.Headers.Where(x => x.ColumnIndex == i)) + { + first = x; + break; + } + var (_, _, _, name) = first; + if (name != null) + { + object? value = config.Data[j]?.GetType().GetProperty(name)!.GetValue(config.Data[j], null); + array[j, i] = value == null + ? config.NullReplace + : value.ToString(); + } + } + } + LoadDataToTableWithMultiHeader(array); + SaveDoc(config.FileName); + } + public void SaveDoc(string filepath) + { + if (string.IsNullOrEmpty(filepath)) + { + throw new ArgumentNullException("Имя файла не задано"); + } + + if (_document == null || _body == null) + { + throw new ArgumentNullException("Документ не сформирован, сохранять нечего"); + } + + if (_table != null) + { + Body.Append(Table); + } + + using WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Create(filepath, WordprocessingDocumentType.Document); + MainDocumentPart mainDocumentPart = wordprocessingDocument.AddMainDocumentPart(); + mainDocumentPart.Document = Document; + } + public void LoadDataToTableWithMultiHeader(string[,] data) + { + for (int i = 0; i < data.GetLength(0); i++) + { + TableRow tablerow = new TableRow(); + for (int j = 0; j < data.GetLength(1); j++) + { + TableCell tableCell = new TableCell(); + tableCell.Append(new Paragraph(new Run(new Text(data[i, j])))); + tablerow.Append(tableCell); + } + Table.Append(tablerow); + } + } + public void CreateMultiHeader(WordTableWithData config) + { + if (config.Headers == null || !config.Headers.Any()) + return; + TableProperties tblProperties = new TableProperties( + new TableWidth { Type = TableWidthUnitValues.Dxa, Width = "5000" }); + Table.AppendChild(tblProperties); + TableRow headerRow = new TableRow(); + foreach (var header in config.Headers.Where(h => h.ColumnIndex >= 0)) + { + TableCell cell = new TableCell(new Paragraph(new Run(new Text(header.Header)))); + TableCellProperties cellProperties = new TableCellProperties( + new TableCellWidth { Type = TableWidthUnitValues.Dxa, Width = (header.ColumnIndex * 100).ToString() }); + cell.AppendChild(cellProperties); + headerRow.AppendChild(cell); + } + + Table.AppendChild(headerRow); + } + + public void CreateTableWithHeader() + { + Table.AppendChild(new TableProperties(new TableBorders(new TopBorder + { + Val = new EnumValue(BorderValues.Single), + Size = (UInt32Value)12u + }, new BottomBorder + { + Val = new EnumValue(BorderValues.Single), + Size = (UInt32Value)12u + }, new LeftBorder + { + Val = new EnumValue(BorderValues.Single), + Size = (UInt32Value)12u + }, new RightBorder + { + Val = new EnumValue(BorderValues.Single), + Size = (UInt32Value)12u + }, new InsideHorizontalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = (UInt32Value)12u + }, new InsideVerticalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = (UInt32Value)12u + }))); + } + + public void CreateHeader(string header) + { + Paragraph paragraph = Body.AppendChild(new Paragraph()); + Run run = paragraph.AppendChild(new Run()); + run.AppendChild(new RunProperties(new Bold())); + run.AppendChild(new Text(header)); + } + } +} \ No newline at end of file diff --git a/README.md b/README.md index a3d9115..6f81066 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# PIbd-33_Radaev_A_V_COP-15 +# PIbd-33_Yunusov_N.N._COP