коммит для димы долгова
This commit is contained in:
parent
fd26a4f7d0
commit
27ea0895d3
@ -8,6 +8,8 @@ namespace KOP_Labs.Classes
|
||||
{
|
||||
public class Book
|
||||
{
|
||||
|
||||
public string Author { get; private set; } = string.Empty;
|
||||
public int Id { get; private set; }
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
@ -18,8 +20,9 @@ namespace KOP_Labs.Classes
|
||||
{
|
||||
|
||||
}
|
||||
public Book(int id, string name, string annotation)
|
||||
public Book(string author, int id, string name, string annotation)
|
||||
{
|
||||
Author = author;
|
||||
Id = id;
|
||||
Name = name;
|
||||
Annotation = annotation;
|
||||
|
21
KOP_Labs/Classes/ColumnParameters.cs
Normal file
21
KOP_Labs/Classes/ColumnParameters.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KOP_Labs.Classes
|
||||
{
|
||||
public class ColumnParameters
|
||||
{
|
||||
public string _nameColumn { get; set; } = string.Empty;
|
||||
|
||||
public string _nameField { get; set; } = string.Empty;
|
||||
|
||||
public ColumnParameters(string nameColumn, string nameField)
|
||||
{
|
||||
_nameColumn = nameColumn;
|
||||
_nameField = nameField;
|
||||
}
|
||||
}
|
||||
}
|
24
KOP_Labs/Classes/DataHistogramm.cs
Normal file
24
KOP_Labs/Classes/DataHistogramm.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KOP_Labs.Classes
|
||||
{
|
||||
public class DataHistogramm
|
||||
{
|
||||
public string _nameSeries { get; set; } = string.Empty;
|
||||
|
||||
public string _nameData { get; set; } = string.Empty;
|
||||
|
||||
public double _data { get; set; }
|
||||
|
||||
public DataHistogramm(string nameSeries, string nameData, double data)
|
||||
{
|
||||
_nameSeries = nameSeries;
|
||||
_nameData = nameData;
|
||||
_data = data;
|
||||
}
|
||||
}
|
||||
}
|
17
KOP_Labs/Classes/EnumLegends.cs
Normal file
17
KOP_Labs/Classes/EnumLegends.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KOP_Labs.Classes
|
||||
{
|
||||
public enum EnumLegends
|
||||
{
|
||||
None = 0,
|
||||
Left = 1,
|
||||
Right = 2,
|
||||
Top = 3,
|
||||
Bottom = 4
|
||||
}
|
||||
}
|
30
KOP_Labs/Classes/MyHistogramm.cs
Normal file
30
KOP_Labs/Classes/MyHistogramm.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using DocumentFormat.OpenXml.Drawing;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KOP_Labs.Classes
|
||||
{
|
||||
public class MyHistogramm
|
||||
{
|
||||
public string _filePath = string.Empty;
|
||||
|
||||
public string _fileHeader = string.Empty;
|
||||
|
||||
public string _histogramName = string.Empty;
|
||||
|
||||
public EnumLegends _legends;
|
||||
|
||||
public List<DataHistogramm> _dataList = new();
|
||||
public MyHistogramm(string filePath, string fileHeader, string histogramName, EnumLegends legends, List<DataHistogramm> dataList) {
|
||||
_filePath = filePath;
|
||||
_fileHeader = fileHeader;
|
||||
_histogramName = histogramName;
|
||||
_legends = legends;
|
||||
_dataList = dataList;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
22
KOP_Labs/Classes/MyTable.cs
Normal file
22
KOP_Labs/Classes/MyTable.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KOP_Labs.Classes
|
||||
{
|
||||
public class MyTable
|
||||
{
|
||||
public string _filePath = string.Empty;
|
||||
|
||||
public string _fileHeader = string.Empty;
|
||||
public List<string[,]> _dataList = new();
|
||||
public MyTable(string filePath, string fileHeader, List<string[,]> dataList) {
|
||||
_filePath = filePath;
|
||||
_fileHeader = fileHeader;
|
||||
_dataList = dataList;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
37
KOP_Labs/Classes/MyTableWithHead.cs
Normal file
37
KOP_Labs/Classes/MyTableWithHead.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KOP_Labs.Classes
|
||||
{
|
||||
public class MyTableWithHead<T>
|
||||
{
|
||||
public string _filePath = string.Empty;
|
||||
|
||||
public string _fileHeader = string.Empty;
|
||||
|
||||
//высота столбцов
|
||||
public List<double> _heightRow = new();
|
||||
|
||||
//высота колонок
|
||||
public List<double> _widthCol = new();
|
||||
|
||||
public List<T> _dataList;
|
||||
|
||||
//настройки соответствия столбец-поле
|
||||
public Dictionary<int, ColumnParameters> _columnsSettings;
|
||||
|
||||
public MyTableWithHead(string filePath, string fileHeader, List<double> heightRow,
|
||||
List<double> widthCol, List<T> dataList, Dictionary<int, ColumnParameters> columnsSettings)
|
||||
{
|
||||
_filePath = filePath;
|
||||
_fileHeader = fileHeader;
|
||||
_heightRow = heightRow;
|
||||
_widthCol = widthCol;
|
||||
_dataList = dataList;
|
||||
_columnsSettings = columnsSettings;
|
||||
}
|
||||
}
|
||||
}
|
27
KOP_Labs/Classes/TableParameters.cs
Normal file
27
KOP_Labs/Classes/TableParameters.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using DocumentFormat.OpenXml.Bibliography;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KOP_Labs.Classes
|
||||
{
|
||||
public class TableParameters
|
||||
{
|
||||
|
||||
public string? _header { get; set; }
|
||||
public int _width { get; set; }
|
||||
public bool _isVisual { get; set; }
|
||||
public string? _name { get; set; }
|
||||
|
||||
public TableParameters(string header, int width, bool isVisual, string name)
|
||||
{
|
||||
|
||||
_header = header;
|
||||
_width = width;
|
||||
_isVisual = isVisual;
|
||||
_name = name;
|
||||
}
|
||||
}
|
||||
}
|
@ -8,7 +8,8 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="NonVisualComponents\" />
|
||||
<PackageReference Include="Aspose.Words" Version="23.10.0" />
|
||||
<PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
36
KOP_Labs/NonVisualComponents/WordHistogramm.Designer.cs
generated
Normal file
36
KOP_Labs/NonVisualComponents/WordHistogramm.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
||||
namespace KOP_Labs.NonVisualComponents
|
||||
{
|
||||
partial class WordHistogramm
|
||||
{
|
||||
/// <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
|
||||
}
|
||||
}
|
88
KOP_Labs/NonVisualComponents/WordHistogramm.cs
Normal file
88
KOP_Labs/NonVisualComponents/WordHistogramm.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using Aspose.Words;
|
||||
using Aspose.Words.Drawing;
|
||||
using Aspose.Words.Drawing.Charts;
|
||||
using KOP_Labs.Classes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KOP_Labs.NonVisualComponents
|
||||
{
|
||||
public partial class WordHistogramm : Component
|
||||
{
|
||||
public WordHistogramm()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public WordHistogramm(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void CreateHistogramm(MyHistogramm myHistogramm)
|
||||
{
|
||||
if(CheckData(myHistogramm._dataList)) {
|
||||
return;
|
||||
}
|
||||
Document doc = new Document();
|
||||
DocumentBuilder builder = new DocumentBuilder(doc);
|
||||
|
||||
Aspose.Words.Font font = builder.Font;
|
||||
font.Size = 14;
|
||||
font.Bold = true;
|
||||
font.Color = System.Drawing.Color.Black;
|
||||
font.Name = "Times New Roman";
|
||||
|
||||
ParagraphFormat paragraphFormat = builder.ParagraphFormat;
|
||||
paragraphFormat.FirstLineIndent = 8;
|
||||
paragraphFormat.SpaceAfter = 24;
|
||||
paragraphFormat.Alignment = ParagraphAlignment.Center;
|
||||
paragraphFormat.KeepTogether = true;
|
||||
|
||||
builder.Writeln(myHistogramm._fileHeader);
|
||||
|
||||
Shape shape = builder.InsertChart(ChartType.Column, 500, 270);
|
||||
Chart chart = shape.Chart;
|
||||
chart.Title.Text = myHistogramm._fileHeader;
|
||||
ChartSeriesCollection seriesColl = chart.Series;
|
||||
|
||||
seriesColl.Clear();
|
||||
|
||||
string[] categories = new string[] { myHistogramm._dataList[0]._nameData };
|
||||
|
||||
|
||||
foreach (var data in myHistogramm._dataList)
|
||||
{
|
||||
seriesColl.Add(data._nameData, categories, new double[] { data._data });
|
||||
}
|
||||
|
||||
ChartLegend legend = chart.Legend;
|
||||
|
||||
legend.Position = (LegendPosition)myHistogramm._legends;
|
||||
legend.Overlay = true;
|
||||
|
||||
|
||||
doc.Save(myHistogramm._filePath);
|
||||
|
||||
}
|
||||
private bool CheckData(List<DataHistogramm> data)
|
||||
{
|
||||
foreach (var _data in data)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_data._nameSeries) || string.IsNullOrEmpty(_data._data.ToString()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
36
KOP_Labs/NonVisualComponents/WordTableComponent.Designer.cs
generated
Normal file
36
KOP_Labs/NonVisualComponents/WordTableComponent.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
||||
namespace KOP_Labs.NonVisualComponents
|
||||
{
|
||||
partial class WordTableComponent
|
||||
{
|
||||
/// <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
|
||||
}
|
||||
}
|
166
KOP_Labs/NonVisualComponents/WordTableComponent.cs
Normal file
166
KOP_Labs/NonVisualComponents/WordTableComponent.cs
Normal file
@ -0,0 +1,166 @@
|
||||
|
||||
using DocumentFormat.OpenXml;
|
||||
using DocumentFormat.OpenXml.ExtendedProperties;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
|
||||
using KOP_Labs.Classes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
using Bold = DocumentFormat.OpenXml.Wordprocessing.Bold;
|
||||
using BottomBorder = DocumentFormat.OpenXml.Wordprocessing.BottomBorder;
|
||||
using LeftBorder = DocumentFormat.OpenXml.Wordprocessing.LeftBorder;
|
||||
using RightBorder = DocumentFormat.OpenXml.Wordprocessing.RightBorder;
|
||||
using Run = DocumentFormat.OpenXml.Wordprocessing.Run;
|
||||
using RunProperties = DocumentFormat.OpenXml.Wordprocessing.RunProperties;
|
||||
using Table = DocumentFormat.OpenXml.Wordprocessing.Table;
|
||||
using Text = DocumentFormat.OpenXml.Wordprocessing.Text;
|
||||
using TopBorder = DocumentFormat.OpenXml.Wordprocessing.TopBorder;
|
||||
|
||||
namespace KOP_Labs.NonVisualComponents
|
||||
{
|
||||
public partial class WordTableComponent : Component
|
||||
{
|
||||
private WordprocessingDocument? _wordDocument;
|
||||
|
||||
private Body? _docBody;
|
||||
|
||||
public WordTableComponent()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public WordTableComponent(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void CreateDoc(MyTable myTable)
|
||||
{
|
||||
if(!CheckData(myTable._dataList)) return;
|
||||
_wordDocument = WordprocessingDocument.Create(myTable._filePath, WordprocessingDocumentType.Document);
|
||||
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
|
||||
|
||||
mainPart.Document = new Document();
|
||||
_docBody = mainPart.Document.AppendChild(new Body());
|
||||
_wordDocument.Close();
|
||||
|
||||
using (WordprocessingDocument doc = WordprocessingDocument.Open(myTable._filePath, true))
|
||||
{
|
||||
|
||||
var mainDoc = doc.MainDocumentPart.Document;
|
||||
mainPart.Document = new Document();
|
||||
Body body = mainPart.Document.AppendChild(new Body());
|
||||
|
||||
Paragraph headerParagraph = new Paragraph();
|
||||
|
||||
Run headerRun = new Run(new Text(myTable._fileHeader));
|
||||
RunProperties runProperties = new RunProperties();
|
||||
Bold bold = new Bold();
|
||||
runProperties.Append(bold);
|
||||
|
||||
headerRun.Append(runProperties);
|
||||
|
||||
headerParagraph.Append(headerRun);
|
||||
|
||||
Table table = new Table();
|
||||
|
||||
TableProperties props = new TableProperties(
|
||||
new TableBorders(
|
||||
new TopBorder
|
||||
{
|
||||
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
},
|
||||
new BottomBorder
|
||||
{
|
||||
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
},
|
||||
new LeftBorder
|
||||
{
|
||||
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
},
|
||||
new RightBorder
|
||||
{
|
||||
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
},
|
||||
new InsideHorizontalBorder
|
||||
{
|
||||
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
},
|
||||
new InsideVerticalBorder
|
||||
{
|
||||
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
}
|
||||
));
|
||||
|
||||
table.AppendChild<TableProperties>(props);
|
||||
for (var i = 0; i < myTable._dataList.Count; i++)
|
||||
{
|
||||
var tr = new TableRow();
|
||||
|
||||
for (var j = 0; j < myTable._dataList[i].Length; j++)
|
||||
{
|
||||
var tc = new TableCell();
|
||||
|
||||
tc.Append(new TableCellProperties(new TableCellWidth
|
||||
{
|
||||
Type = TableWidthUnitValues.Dxa,
|
||||
Width = "2000"
|
||||
}
|
||||
));
|
||||
|
||||
tc.Append(new Paragraph(new Run(new Text(myTable._dataList[i][0, j]))));
|
||||
|
||||
tr.Append(tc);
|
||||
}
|
||||
|
||||
table.Append(tr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
mainDoc.Body.Append(headerParagraph);
|
||||
mainDoc.Body.Append(table);
|
||||
|
||||
|
||||
mainDoc.Save();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private bool CheckData(List<string[,]> data)
|
||||
{
|
||||
for (int i = 0; i < data.Count; i++)
|
||||
{
|
||||
for (int j = 0; j < data[i].Length; j++)
|
||||
{
|
||||
if (data[i][0, j] == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
36
KOP_Labs/NonVisualComponents/WordTableHeaderComponent.Designer.cs
generated
Normal file
36
KOP_Labs/NonVisualComponents/WordTableHeaderComponent.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
||||
namespace KOP_Labs.NonVisualComponents
|
||||
{
|
||||
partial class WordTableHeaderComponent
|
||||
{
|
||||
/// <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
|
||||
}
|
||||
}
|
243
KOP_Labs/NonVisualComponents/WordTableHeaderComponent.cs
Normal file
243
KOP_Labs/NonVisualComponents/WordTableHeaderComponent.cs
Normal file
@ -0,0 +1,243 @@
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml;
|
||||
using KOP_Labs.Classes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
|
||||
namespace KOP_Labs.NonVisualComponents
|
||||
{
|
||||
public partial class WordTableHeaderComponent : Component
|
||||
{
|
||||
private WordprocessingDocument? _wordDocument;
|
||||
|
||||
private Body? _docBody;
|
||||
public WordTableHeaderComponent()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public WordTableHeaderComponent(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void CreateDoc<T>(MyTableWithHead<T> myTable)
|
||||
{
|
||||
if (!CheckData(myTable._dataList)) return;
|
||||
_wordDocument = WordprocessingDocument.Create(myTable._filePath, WordprocessingDocumentType.Document);
|
||||
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
|
||||
|
||||
mainPart.Document = new Document();
|
||||
|
||||
_docBody = mainPart.Document.AppendChild(new Body());
|
||||
_wordDocument.Close();
|
||||
|
||||
using (WordprocessingDocument doc = WordprocessingDocument.Open(myTable._filePath, true))
|
||||
{
|
||||
|
||||
var mainDoc = doc.MainDocumentPart.Document;
|
||||
mainPart.Document = new Document();
|
||||
Body body = mainPart.Document.AppendChild(new Body());
|
||||
|
||||
|
||||
Paragraph headerParagraph = new Paragraph();
|
||||
Run headerRun = new Run(new Text(myTable._fileHeader));
|
||||
|
||||
RunProperties runProperties = new RunProperties();
|
||||
Bold bold = new Bold();
|
||||
runProperties.Append(bold);
|
||||
headerRun.Append(runProperties);
|
||||
|
||||
headerParagraph.Append(headerRun);
|
||||
|
||||
|
||||
Table table = new Table();
|
||||
|
||||
TableProperties props = new TableProperties(
|
||||
new TableBorders(
|
||||
new TopBorder
|
||||
{
|
||||
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
},
|
||||
new BottomBorder
|
||||
{
|
||||
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
},
|
||||
new LeftBorder
|
||||
{
|
||||
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
},
|
||||
new RightBorder
|
||||
{
|
||||
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
},
|
||||
new InsideHorizontalBorder
|
||||
{
|
||||
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
},
|
||||
new InsideVerticalBorder
|
||||
{
|
||||
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
}
|
||||
));
|
||||
|
||||
table.AppendChild<TableProperties>(props);
|
||||
|
||||
var _tr = new TableRow();
|
||||
|
||||
int indexHeaderHeigh = 0;
|
||||
int indexHeaderWidth = 0;
|
||||
|
||||
foreach (var item in myTable._columnsSettings)
|
||||
{
|
||||
_tr.Append(new TableRowProperties(new TableRowHeight
|
||||
{
|
||||
Val = Convert.ToUInt32(myTable._heightRow[indexHeaderHeigh])
|
||||
}));
|
||||
|
||||
var tc = new TableCell();
|
||||
|
||||
tc.Append(new TableCellProperties(new TableCellWidth
|
||||
{
|
||||
Type = TableWidthUnitValues.Dxa,
|
||||
Width = myTable._widthCol[indexHeaderWidth].ToString(),
|
||||
}
|
||||
));
|
||||
|
||||
if (string.IsNullOrEmpty(myTable._columnsSettings[indexHeaderWidth]._nameField) ||
|
||||
string.IsNullOrEmpty(myTable._columnsSettings[indexHeaderWidth]._nameColumn))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Paragraph tableHeader = new();
|
||||
|
||||
var Run = new Run();
|
||||
|
||||
var headerProperties = new RunProperties();
|
||||
|
||||
headerProperties.Append(new Bold());
|
||||
|
||||
Run.AppendChild(headerProperties);
|
||||
|
||||
Run.AppendChild(new Text(item.Value._nameColumn));
|
||||
|
||||
tableHeader.AppendChild(Run);
|
||||
|
||||
tc.Append(tableHeader);
|
||||
|
||||
_tr.Append(tc);
|
||||
|
||||
indexHeaderWidth++;
|
||||
}
|
||||
|
||||
table.Append(_tr);
|
||||
|
||||
|
||||
indexHeaderHeigh++;
|
||||
indexHeaderWidth = 0;
|
||||
|
||||
|
||||
|
||||
for (int i = 1; i < myTable._dataList.Count; i++)
|
||||
{
|
||||
var tr = new TableRow();
|
||||
|
||||
|
||||
foreach (var item in myTable._columnsSettings)
|
||||
{
|
||||
tr.Append(new TableRowProperties(new TableRowHeight
|
||||
{
|
||||
Val = Convert.ToUInt32(myTable._heightRow[indexHeaderHeigh])
|
||||
}));
|
||||
|
||||
var tc = new TableCell();
|
||||
|
||||
tc.Append(new TableCellProperties(new TableCellWidth
|
||||
{
|
||||
Type = TableWidthUnitValues.Dxa,
|
||||
Width = myTable._widthCol[indexHeaderWidth].ToString(),
|
||||
}
|
||||
));
|
||||
|
||||
|
||||
foreach (var val in myTable._dataList[i].GetType().GetProperties())
|
||||
{
|
||||
if (val.Name == item.Value._nameField)
|
||||
{
|
||||
var newParagraph = new Paragraph();
|
||||
|
||||
var newRun = new Run();
|
||||
|
||||
var runPropertiesInd = new RunProperties();
|
||||
|
||||
if (indexHeaderWidth == 0)
|
||||
{
|
||||
runPropertiesInd.Append(new Bold());
|
||||
}
|
||||
|
||||
newRun.AppendChild(runPropertiesInd);
|
||||
|
||||
newRun.AppendChild(new Text(val.GetValue(myTable._dataList[i]).ToString()));
|
||||
|
||||
newParagraph.AppendChild(newRun);
|
||||
|
||||
tc.Append(newParagraph);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
tr.Append(tc);
|
||||
|
||||
indexHeaderWidth++;
|
||||
}
|
||||
|
||||
indexHeaderWidth = 0;
|
||||
|
||||
table.Append(tr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
mainDoc.Body.Append(headerParagraph);
|
||||
|
||||
mainDoc.Body.Append(table);
|
||||
|
||||
mainDoc.Save();
|
||||
}
|
||||
}
|
||||
|
||||
private bool CheckData<T>(List<T> dataList)
|
||||
{
|
||||
foreach (var data in dataList)
|
||||
{
|
||||
foreach (var value in data.GetType().GetProperties())
|
||||
{
|
||||
|
||||
if (string.IsNullOrEmpty(value.GetValue(data).ToString()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using KOP_Labs.Classes;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -33,16 +34,16 @@ namespace KOP_Labs
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
public void TableConfiguration(int columnsQuantity, List<string> headers, List<int> widths, List<bool> isVisual, List<string> names)
|
||||
public void TableConfiguration(int countCol, List<TableParameters> parameters)
|
||||
{
|
||||
for (int i = 0; i < columnsQuantity; i++)
|
||||
|
||||
if (parameters.Count != parameters.Count) { return; }
|
||||
for (int i = 0; i < countCol; i++)
|
||||
{
|
||||
DataGridViewColumn column = new DataGridViewColumn();
|
||||
column.Name = names[i];
|
||||
column.HeaderText = headers[i];
|
||||
column.Width = widths[i];
|
||||
column.Visible = isVisual[i];
|
||||
column.Name = parameters[i]._name;
|
||||
column.HeaderText = parameters[i]._header;
|
||||
column.Width = parameters[i]._width;
|
||||
column.Visible = parameters[i]._isVisual;
|
||||
column.CellTemplate = new DataGridViewTextBoxCell();
|
||||
|
||||
dataGridView.Columns.Add(column);
|
||||
|
@ -1,4 +1,5 @@
|
||||
using KOP_Labs.Exceptions;
|
||||
using DocumentFormat.OpenXml.Drawing.Diagrams;
|
||||
using KOP_Labs.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -38,6 +39,7 @@ namespace KOP_Labs
|
||||
|
||||
return null;
|
||||
|
||||
|
||||
}
|
||||
set
|
||||
{
|
||||
|
@ -54,11 +54,12 @@ namespace WinForm
|
||||
|
||||
private void buttonConfig_Click(object sender, EventArgs e)
|
||||
{
|
||||
tableComponent.TableConfiguration(3,
|
||||
new List<string>() { "fds", "fds", "fds" },
|
||||
new List<int>() { 80, 80, 80 },
|
||||
new List<bool> { true, true, true },
|
||||
new List<string> { "Id", "Name", "Annotation" });
|
||||
List<TableParameters> tableParameters = new List<TableParameters>();
|
||||
tableParameters.Add(new TableParameters("fds", 80, true, "Id"));
|
||||
tableParameters.Add(new TableParameters("fds", 80, true, "Name"));
|
||||
tableParameters.Add(new TableParameters("fds", 80, true, "Annotation"));
|
||||
|
||||
tableComponent.TableConfiguration(3, tableParameters);
|
||||
}
|
||||
|
||||
private void buttonCleatTable_Click(object sender, EventArgs e)
|
||||
|
92
WinForm/NonVisualForm.Designer.cs
generated
Normal file
92
WinForm/NonVisualForm.Designer.cs
generated
Normal file
@ -0,0 +1,92 @@
|
||||
namespace WinForm
|
||||
{
|
||||
partial class NonVisualForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
wordTableComponent1 = new KOP_Labs.NonVisualComponents.WordTableComponent(components);
|
||||
buttonWordSave = new Button();
|
||||
buttonSaveHist = new Button();
|
||||
wordHistogramm1 = new KOP_Labs.NonVisualComponents.WordHistogramm(components);
|
||||
wordTableHeaderComponent1 = new KOP_Labs.NonVisualComponents.WordTableHeaderComponent(components);
|
||||
buttonHead = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// buttonWordSave
|
||||
//
|
||||
buttonWordSave.Location = new Point(54, 262);
|
||||
buttonWordSave.Name = "buttonWordSave";
|
||||
buttonWordSave.Size = new Size(94, 29);
|
||||
buttonWordSave.TabIndex = 0;
|
||||
buttonWordSave.Text = "Сохранить";
|
||||
buttonWordSave.UseVisualStyleBackColor = true;
|
||||
buttonWordSave.Click += buttonWordSave_Click;
|
||||
//
|
||||
// buttonSaveHist
|
||||
//
|
||||
buttonSaveHist.Location = new Point(279, 262);
|
||||
buttonSaveHist.Name = "buttonSaveHist";
|
||||
buttonSaveHist.Size = new Size(94, 29);
|
||||
buttonSaveHist.TabIndex = 1;
|
||||
buttonSaveHist.Text = "xlsx";
|
||||
buttonSaveHist.UseVisualStyleBackColor = true;
|
||||
buttonSaveHist.Click += buttonSaveHist_Click;
|
||||
//
|
||||
// buttonHead
|
||||
//
|
||||
buttonHead.Location = new Point(499, 262);
|
||||
buttonHead.Name = "buttonHead";
|
||||
buttonHead.Size = new Size(169, 29);
|
||||
buttonHead.TabIndex = 2;
|
||||
buttonHead.Text = "Таблица с шапкой";
|
||||
buttonHead.UseVisualStyleBackColor = true;
|
||||
buttonHead.Click += buttonHead_Click;
|
||||
//
|
||||
// NonVisualForm
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(buttonHead);
|
||||
Controls.Add(buttonSaveHist);
|
||||
Controls.Add(buttonWordSave);
|
||||
Name = "NonVisualForm";
|
||||
Text = "NonVisualForm";
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private KOP_Labs.NonVisualComponents.WordTableComponent wordTableComponent1;
|
||||
private Button buttonWordSave;
|
||||
private Button buttonSaveHist;
|
||||
private KOP_Labs.NonVisualComponents.WordHistogramm wordHistogramm1;
|
||||
private KOP_Labs.NonVisualComponents.WordTableHeaderComponent wordTableHeaderComponent1;
|
||||
private Button buttonHead;
|
||||
}
|
||||
}
|
88
WinForm/NonVisualForm.cs
Normal file
88
WinForm/NonVisualForm.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using DocumentFormat.OpenXml.Bibliography;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using KOP_Labs.Classes;
|
||||
using Microsoft.VisualBasic.ApplicationServices;
|
||||
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 WinForm
|
||||
{
|
||||
public partial class NonVisualForm : Form
|
||||
{
|
||||
public NonVisualForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
MyHistogramm histogram;
|
||||
|
||||
|
||||
private void buttonWordSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
string filePath = "C:\\Users\\User\\Desktop\\универ\\3курс\\КОП\\Отчет.docx";
|
||||
string title = "Заголовок";
|
||||
string[,] row1 = {
|
||||
{ "Стр1 Кол1", "Стр1 Кол2" }
|
||||
};
|
||||
|
||||
string[,] row2 = {
|
||||
{ "Стр2 Кол1", "Стр2 Кол2" }
|
||||
};
|
||||
|
||||
string[,] row3 = {
|
||||
{ "Стр3 Кол1", "Стр3 Кол3" }
|
||||
};
|
||||
MyTable table = new MyTable(filePath, title, new List<string[,]> { row1, row2, row3 });
|
||||
wordTableComponent1.CreateDoc(table);
|
||||
|
||||
}
|
||||
|
||||
private void buttonSaveHist_Click(object sender, EventArgs e)
|
||||
{
|
||||
histogram = new("C:\\Users\\User\\Desktop\\универ\\3курс\\КОП\\Report.docx", "Третье задание", "Гистограмма", EnumLegends.Right, new List<DataHistogramm> {
|
||||
new DataHistogramm("Доход", "Январь", 300), new DataHistogramm("Доход", "Апрель", 600),
|
||||
new DataHistogramm("Доход", "Июль", 400), new DataHistogramm("Доход", "Октябрь", 200)
|
||||
});
|
||||
|
||||
wordHistogramm1.CreateHistogramm(histogram);
|
||||
|
||||
}
|
||||
|
||||
List<Book> books;
|
||||
Book book1 = new Book(1, "fgdf", "fdsds");
|
||||
Book book2 = new Book(1, "aa", "fdads");
|
||||
Book book3 = new Book(1, "fgdf", "ffsds");
|
||||
Book book4 = new Book(1, "ffdsff", "asds");
|
||||
Book book5 = new Book(1, "ffdsff", "asds");
|
||||
|
||||
Dictionary<int, ColumnParameters> colData;
|
||||
private void buttonHead_Click(object sender, EventArgs e)
|
||||
{
|
||||
books = new()
|
||||
{
|
||||
book1, book2, book3, book4, book5
|
||||
};
|
||||
|
||||
colData = new Dictionary<int, ColumnParameters>()
|
||||
{
|
||||
{ 0, new ColumnParameters("Марка автомобиля", "Id") },
|
||||
{ 1, new ColumnParameters("Модель", "Name") },
|
||||
{ 2, new ColumnParameters("Год выпуска", "Annotation") }
|
||||
|
||||
};
|
||||
MyTableWithHead<Book> myTable;
|
||||
//сгруппируй
|
||||
myTable = new("C:\\Users\\User\\Desktop\\универ\\3курс\\КОП\\Report2.docx", "Второе задание", new List<double> { 48, 24 },
|
||||
new List<double> { 2000, 2000, 1500, 1500 }, books, colData);
|
||||
wordTableHeaderComponent1.CreateDoc(myTable);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
69
WinForm/NonVisualForm.resx
Normal file
69
WinForm/NonVisualForm.resx
Normal file
@ -0,0 +1,69 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="wordTableComponent1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="wordHistogramm1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>230, 17</value>
|
||||
</metadata>
|
||||
<metadata name="wordTableHeaderComponent1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>410, 17</value>
|
||||
</metadata>
|
||||
</root>
|
@ -11,7 +11,7 @@ namespace WinForm
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form1());
|
||||
Application.Run(new NonVisualForm());
|
||||
}
|
||||
}
|
||||
}
|
@ -8,6 +8,10 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Office.Interop.Word" Version="15.0.4797.1004" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\KOP_Labs\KOP_Labs.csproj" />
|
||||
</ItemGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user