lab-3 excel table report issues

This commit is contained in:
strwbrry1 2024-12-23 23:23:08 +04:00
parent 39b6bc7ef5
commit 21405b404e
13 changed files with 1291 additions and 18 deletions

View File

@ -36,8 +36,10 @@
типографияToolStripMenuItem = new ToolStripMenuItem();
операцииToolStripMenuItem = new ToolStripMenuItem();
получениеМатериаловToolStripMenuItem = new ToolStripMenuItem();
отчетыToolStripMenuItem = new ToolStripMenuItem();
заказToolStripMenuItem = new ToolStripMenuItem();
отчетыToolStripMenuItem = new ToolStripMenuItem();
документСоСправочникамиToolStripMenuItem = new ToolStripMenuItem();
таблицаСОперациямиToolStripMenuItem = new ToolStripMenuItem();
menuStrip1.SuspendLayout();
SuspendLayout();
//
@ -47,7 +49,8 @@
menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, операцииToolStripMenuItem, отчетыToolStripMenuItem });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Size = new Size(800, 28);
menuStrip1.Padding = new Padding(5, 2, 0, 2);
menuStrip1.Size = new Size(700, 24);
menuStrip1.TabIndex = 0;
menuStrip1.Text = "menuStrip1";
//
@ -55,34 +58,34 @@
//
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { покупательToolStripMenuItem, контактнаяПерсонаToolStripMenuItem, материалыToolStripMenuItem, типографияToolStripMenuItem });
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
справочникиToolStripMenuItem.Size = new Size(117, 24);
справочникиToolStripMenuItem.Size = new Size(94, 20);
справочникиToolStripMenuItem.Text = "Справочники";
//
// покупательToolStripMenuItem
//
покупательToolStripMenuItem.Name = "покупательToolStripMenuItem";
покупательToolStripMenuItem.Size = new Size(234, 26);
покупательToolStripMenuItem.Size = new Size(185, 22);
покупательToolStripMenuItem.Text = "Покупатель";
покупательToolStripMenuItem.Click += покупательToolStripMenuItem_Click;
//
// контактнаяПерсонаToolStripMenuItem
//
контактнаяПерсонаToolStripMenuItem.Name = онтактнаяПерсонаToolStripMenuItem";
контактнаяПерсонаToolStripMenuItem.Size = new Size(234, 26);
контактнаяПерсонаToolStripMenuItem.Size = new Size(185, 22);
контактнаяПерсонаToolStripMenuItem.Text = "Контактная персона";
контактнаяПерсонаToolStripMenuItem.Click += контактнаяПерсонаToolStripMenuItem_Click;
//
// материалыToolStripMenuItem
//
материалыToolStripMenuItem.Name = атериалыToolStripMenuItem";
материалыToolStripMenuItem.Size = new Size(234, 26);
материалыToolStripMenuItem.Size = new Size(185, 22);
материалыToolStripMenuItem.Text = "Материалы";
материалыToolStripMenuItem.Click += материалыToolStripMenuItem_Click;
//
// типографияToolStripMenuItem
//
типографияToolStripMenuItem.Name = "типографияToolStripMenuItem";
типографияToolStripMenuItem.Size = new Size(234, 26);
типографияToolStripMenuItem.Size = new Size(185, 22);
типографияToolStripMenuItem.Text = "Типография";
типографияToolStripMenuItem.Click += типографияToolStripMenuItem_Click;
//
@ -90,36 +93,54 @@
//
операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { получениеМатериаловToolStripMenuItem, заказToolStripMenuItem });
операцииToolStripMenuItem.Name = "операцииToolStripMenuItem";
операцииToolStripMenuItem.Size = new Size(95, 24);
операцииToolStripMenuItem.Size = new Size(75, 20);
операцииToolStripMenuItem.Text = "Операции";
//
// получениеМатериаловToolStripMenuItem
//
получениеМатериаловToolStripMenuItem.Name = "получениеМатериаловToolStripMenuItem";
получениеМатериаловToolStripMenuItem.Size = new Size(257, 26);
получениеМатериаловToolStripMenuItem.Size = new Size(205, 22);
получениеМатериаловToolStripMenuItem.Text = "Получение материалов";
получениеМатериаловToolStripMenuItem.Click += получениеМатериаловToolStripMenuItem_Click;
//
// отчетыToolStripMenuItem
//
отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
отчетыToolStripMenuItem.Size = new Size(73, 24);
отчетыToolStripMenuItem.Text = "Отчеты";
//
// заказToolStripMenuItem
//
заказToolStripMenuItem.Name = аказToolStripMenuItem";
заказToolStripMenuItem.Size = new Size(257, 26);
заказToolStripMenuItem.Size = new Size(205, 22);
заказToolStripMenuItem.Text = "Заказ";
заказToolStripMenuItem.Click += заказToolStripMenuItem_Click;
//
// отчетыToolStripMenuItem
//
отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { документСоСправочникамиToolStripMenuItem, таблицаСОперациямиToolStripMenuItem });
отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
отчетыToolStripMenuItem.Size = new Size(60, 20);
отчетыToolStripMenuItem.Text = "Отчеты";
//
// документСоСправочникамиToolStripMenuItem
//
документСоСправочникамиToolStripMenuItem.Name = окументСоСправочникамиToolStripMenuItem";
документСоСправочникамиToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.W;
документСоСправочникамиToolStripMenuItem.Size = new Size(280, 22);
документСоСправочникамиToolStripMenuItem.Text = "Документ со справочниками";
документСоСправочникамиToolStripMenuItem.Click += документСоСправочникамиToolStripMenuItem_Click;
//
// таблицаСОперациямиToolStripMenuItem
//
таблицаСОперациямиToolStripMenuItem.Name = аблицаСОперациямиToolStripMenuItem";
таблицаСОперациямиToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.T;
таблицаСОперациямиToolStripMenuItem.Size = new Size(280, 22);
таблицаСОперациямиToolStripMenuItem.Text = "Таблица с операциями";
таблицаСОперациямиToolStripMenuItem.Click += таблицаСОперациямиToolStripMenuItem_Click;
//
// FormPublishing
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
ClientSize = new Size(700, 338);
Controls.Add(menuStrip1);
MainMenuStrip = menuStrip1;
Margin = new Padding(3, 2, 3, 2);
Name = "FormPublishing";
Text = "Издательство";
menuStrip1.ResumeLayout(false);
@ -140,5 +161,7 @@
private ToolStripMenuItem получениеМатериаловToolStripMenuItem;
private ToolStripMenuItem отчетыToolStripMenuItem;
private ToolStripMenuItem заказToolStripMenuItem;
private ToolStripMenuItem документСоСправочникамиToolStripMenuItem;
private ToolStripMenuItem таблицаСОперациямиToolStripMenuItem;
}
}

View File

@ -83,5 +83,29 @@ namespace ProjectPublishing
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void äîêóìåíòÑîÑïðàâî÷íèêàìèToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormDirectoryReport>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void òàáëèöàÑÎïåðàöèÿìèToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormMaterialsReport>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -0,0 +1,112 @@
namespace ProjectPublishing.Forms
{
partial class FormDirectoryReport
{
/// <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()
{
checkBoxCustomers = new CheckBox();
checkBoxPrintingHouses = new CheckBox();
checkBoxMaterials = new CheckBox();
checkBoxContactPeople = new CheckBox();
buttonBuild = new Button();
SuspendLayout();
//
// checkBoxCustomers
//
checkBoxCustomers.AutoSize = true;
checkBoxCustomers.Location = new Point(12, 12);
checkBoxCustomers.Name = "checkBoxCustomers";
checkBoxCustomers.Size = new Size(83, 19);
checkBoxCustomers.TabIndex = 1;
checkBoxCustomers.Text = "Заказчики";
checkBoxCustomers.UseVisualStyleBackColor = true;
//
// checkBoxPrintingHouses
//
checkBoxPrintingHouses.AutoSize = true;
checkBoxPrintingHouses.Location = new Point(12, 37);
checkBoxPrintingHouses.Name = "checkBoxPrintingHouses";
checkBoxPrintingHouses.Size = new Size(94, 19);
checkBoxPrintingHouses.TabIndex = 2;
checkBoxPrintingHouses.Text = "Типографии";
checkBoxPrintingHouses.UseVisualStyleBackColor = true;
//
// checkBoxMaterials
//
checkBoxMaterials.AutoSize = true;
checkBoxMaterials.Location = new Point(12, 62);
checkBoxMaterials.Name = "checkBoxMaterials";
checkBoxMaterials.Size = new Size(90, 19);
checkBoxMaterials.TabIndex = 3;
checkBoxMaterials.Text = "Материалы";
checkBoxMaterials.UseVisualStyleBackColor = true;
//
// checkBoxContactPeople
//
checkBoxContactPeople.AutoSize = true;
checkBoxContactPeople.Location = new Point(12, 87);
checkBoxContactPeople.Name = "checkBoxContactPeople";
checkBoxContactPeople.Size = new Size(147, 19);
checkBoxContactPeople.TabIndex = 4;
checkBoxContactPeople.Text = "Контактные личности";
checkBoxContactPeople.UseVisualStyleBackColor = true;
//
// buttonBuild
//
buttonBuild.Location = new Point(166, 37);
buttonBuild.Name = "buttonBuild";
buttonBuild.Size = new Size(102, 44);
buttonBuild.TabIndex = 5;
buttonBuild.Text = "Сформировать";
buttonBuild.UseVisualStyleBackColor = true;
buttonBuild.Click += ButtonBuild_Click;
//
// FormDirectoryReport
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(279, 117);
Controls.Add(buttonBuild);
Controls.Add(checkBoxContactPeople);
Controls.Add(checkBoxMaterials);
Controls.Add(checkBoxPrintingHouses);
Controls.Add(checkBoxCustomers);
Name = "FormDirectoryReport";
Text = "FormDirectoryReport";
ResumeLayout(false);
PerformLayout();
}
#endregion
private CheckBox checkBoxCustomers;
private CheckBox checkBoxPrintingHouses;
private CheckBox checkBoxMaterials;
private CheckBox checkBoxContactPeople;
private Button buttonBuild;
}
}

View File

@ -0,0 +1,51 @@
using ProjectPublishing.Reports;
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 Unity;
namespace ProjectPublishing.Forms
{
public partial class FormDirectoryReport : Form
{
private readonly IUnityContainer _container;
public FormDirectoryReport(IUnityContainer container)
{
InitializeComponent();
_container = container ?? throw new ArgumentNullException(nameof(container));
}
private void ButtonBuild_Click(object sender, EventArgs e)
{
try
{
if (!checkBoxCustomers.Checked && !checkBoxPrintingHouses.Checked && !checkBoxMaterials.Checked && !checkBoxContactPeople.Checked)
throw new Exception("Не выбран ни один справочник для выгрузки");
var sfd = new SaveFileDialog()
{
Filter = "Docx Files | *.docx"
};
if (sfd.ShowDialog() != DialogResult.OK)
throw new Exception("Не выбран файла для отчета");
if (_container.Resolve<DocReport>().CreateDoc(sfd.FileName, checkBoxCustomers.Checked, checkBoxPrintingHouses.Checked, checkBoxMaterials.Checked, checkBoxContactPeople.Checked))
MessageBox.Show("Документ сформирован", "Формирование документа", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show("Возникли ошибки при формировании документа.Подробности в логах", "Формирование документа", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при создании отчета", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

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

View File

@ -0,0 +1,162 @@
namespace ProjectPublishing.Forms
{
partial class FormMaterialsReport
{
/// <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()
{
dateTimePickerStart = new DateTimePicker();
dateTimePickerEnd = new DateTimePicker();
label1 = new Label();
label2 = new Label();
comboBoxMaterials = new ComboBox();
label3 = new Label();
label4 = new Label();
textBoxFilePath = new TextBox();
buttonSelectFilePath = new Button();
buttonMakeReport = new Button();
SuspendLayout();
//
// dateTimePickerStart
//
dateTimePickerStart.Location = new Point(136, 137);
dateTimePickerStart.Name = "dateTimePickerStart";
dateTimePickerStart.Size = new Size(200, 23);
dateTimePickerStart.TabIndex = 0;
//
// dateTimePickerEnd
//
dateTimePickerEnd.Location = new Point(136, 178);
dateTimePickerEnd.Name = "dateTimePickerEnd";
dateTimePickerEnd.Size = new Size(200, 23);
dateTimePickerEnd.TabIndex = 1;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(12, 143);
label1.Name = "label1";
label1.Size = new Size(74, 15);
label1.TabIndex = 2;
label1.Text = "Дата начала";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(12, 184);
label2.Name = "label2";
label2.Size = new Size(68, 15);
label2.TabIndex = 3;
label2.Text = "Дата конца";
//
// comboBoxMaterials
//
comboBoxMaterials.FormattingEnabled = true;
comboBoxMaterials.Location = new Point(136, 94);
comboBoxMaterials.Name = "comboBoxMaterials";
comboBoxMaterials.Size = new Size(200, 23);
comboBoxMaterials.TabIndex = 4;
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(12, 97);
label3.Name = "label3";
label3.Size = new Size(62, 15);
label3.TabIndex = 5;
label3.Text = "Материал";
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(12, 46);
label4.Name = "label4";
label4.Size = new Size(80, 15);
label4.TabIndex = 6;
label4.Text = "Путь к файлу";
//
// textBoxFilePath
//
textBoxFilePath.Location = new Point(136, 43);
textBoxFilePath.Name = "textBoxFilePath";
textBoxFilePath.Size = new Size(165, 23);
textBoxFilePath.TabIndex = 7;
//
// buttonSelectFilePath
//
buttonSelectFilePath.Location = new Point(307, 43);
buttonSelectFilePath.Name = "buttonSelectFilePath";
buttonSelectFilePath.Size = new Size(29, 23);
buttonSelectFilePath.TabIndex = 8;
buttonSelectFilePath.Text = ". .";
buttonSelectFilePath.UseVisualStyleBackColor = true;
buttonSelectFilePath.Click += ButtonSelectFilePath_Click;
//
// buttonMakeReport
//
buttonMakeReport.Location = new Point(108, 220);
buttonMakeReport.Name = "buttonMakeReport";
buttonMakeReport.Size = new Size(133, 23);
buttonMakeReport.TabIndex = 9;
buttonMakeReport.Text = "Сформировать";
buttonMakeReport.UseVisualStyleBackColor = true;
buttonMakeReport.Click += ButtonMakeReport_Click;
//
// MaterialsReport
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(348, 255);
Controls.Add(buttonMakeReport);
Controls.Add(buttonSelectFilePath);
Controls.Add(textBoxFilePath);
Controls.Add(label4);
Controls.Add(label3);
Controls.Add(comboBoxMaterials);
Controls.Add(label2);
Controls.Add(label1);
Controls.Add(dateTimePickerEnd);
Controls.Add(dateTimePickerStart);
Name = "MaterialsReport";
Text = "MaterialsReport";
ResumeLayout(false);
PerformLayout();
}
#endregion
private DateTimePicker dateTimePickerStart;
private DateTimePicker dateTimePickerEnd;
private Label label1;
private Label label2;
private ComboBox comboBoxMaterials;
private Label label3;
private Label label4;
private TextBox textBoxFilePath;
private Button buttonSelectFilePath;
private Button buttonMakeReport;
}
}

View File

@ -0,0 +1,67 @@
using ProjectPublishing.Reports;
using ProjectPublishing.Repositories;
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 Unity;
namespace ProjectPublishing.Forms
{
public partial class FormMaterialsReport : Form
{
private string _fileName = string.Empty;
private readonly IUnityContainer _container;
public FormMaterialsReport(IUnityContainer container, IMaterialRepository materialRepository)
{
InitializeComponent();
_container = container ?? throw new ArgumentNullException(nameof(container));
comboBoxMaterials.DataSource = materialRepository.ReadMaterials();
comboBoxMaterials.DisplayMember = "Name";
comboBoxMaterials.ValueMember = "Id";
}
private void ButtonSelectFilePath_Click(object sender, EventArgs e)
{
var sfd = new SaveFileDialog()
{
Filter = "Excel Files | *.xlsx"
};
if (sfd.ShowDialog() != DialogResult.OK)
return;
textBoxFilePath.Text = sfd.FileName;
}
private void ButtonMakeReport_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrWhiteSpace(textBoxFilePath.Text))
throw new Exception("Отсутствует имя файла для отчета");
if (comboBoxMaterials.SelectedIndex < 0 || comboBoxMaterials.SelectedIndex < 0)
throw new Exception("Не выбран материал");
if (dateTimePickerEnd.Value <= dateTimePickerStart.Value)
throw new Exception("Дата начала должна быть раньше даты окончания");
if (_container.Resolve<TableReport>().CreateTable(textBoxFilePath.Text, (int)comboBoxMaterials.SelectedValue!, dateTimePickerStart.Value, dateTimePickerEnd.Value))
MessageBox.Show("Документ сформирован", "Формирование документа", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show("Возникли ошибки при формировании документа.Подробности в логах", "Формирование документа", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при создании очета", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

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

View File

@ -10,6 +10,7 @@
<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="DocumentFormat.OpenXml" Version="3.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />

View File

@ -0,0 +1,96 @@
using Microsoft.Extensions.Logging;
using ProjectPublishing.Entities;
using ProjectPublishing.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectPublishing.Reports
{
public class DocReport
{
private readonly ICustomerRepository _customerRepository;
private readonly IPrintingHouseRepository _printingHouseRepository;
private readonly IMaterialRepository _materialRepository;
private readonly IContactPersonRepository _contactPersonRepository;
private readonly ILogger<DocReport> _logger;
public DocReport(ICustomerRepository customerRepository, IPrintingHouseRepository printingHouseRepository, IMaterialRepository materialRepository, IContactPersonRepository contactPersonRepository, ILogger<DocReport> logger)
{
_customerRepository = customerRepository ?? throw new ArgumentNullException(nameof(customerRepository));
_printingHouseRepository = printingHouseRepository ?? throw new ArgumentNullException(nameof(printingHouseRepository));
_materialRepository = materialRepository ?? throw new ArgumentNullException(nameof(materialRepository));
_contactPersonRepository = contactPersonRepository ?? throw new ArgumentNullException(nameof(contactPersonRepository));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
public bool CreateDoc(string filePath, bool includeCustomer, bool includePrintingHouse, bool includeMaterial, bool includeContactPerson)
{
try
{
var builder = new WordBuilder(filePath).AddHeader("Документ со справочниками");
if (includeCustomer)
builder.AddParagraph("Заказчики").AddTable([2400, 2400, 1200], GetCustomers());
if (includePrintingHouse)
builder.AddParagraph("Типографии").AddTable([2400, 2400, 2400, 2400], GetPrintingHouses());
if (includeMaterial)
builder.AddParagraph("Материалы").AddTable([2400, 1200], GetMaterials());
if (includeContactPerson)
builder.AddParagraph("Контактные личности").AddTable([2400, 2400, 1200], GetContactPeople());
builder.Build();
return true;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при формировании документа");
return false;
}
}
private List<string[]> GetCustomers()
{
return [
["Номер телефона", "Email", "ID типографии"],
.. _customerRepository
.ReadCustomers()
.Select(x => new string[] { x.PhoneNumber, x.Email, x.PublisherId.ToString() }),
];
}
private List<string[]> GetPrintingHouses()
{
return [
["Название", "Адрес", "Номер телефона", "Email"],
.. _printingHouseRepository
.ReadPrintingHouses()
.Select(x => new string[] {x.Name, x.Address, x.PhoneNumber, x.Email }),
];
}
private List<string[]> GetMaterials()
{
return [
["Название", "Тип материала"],
.. _materialRepository
.ReadMaterials()
.Select(x => new string[] {x.Name, x.MaterialType.ToString() }),
];
}
private List<string[]> GetContactPeople()
{
return [
["Имя", "Номер телефона", "Email"],
.. _contactPersonRepository
.ReadContactPeople()
.Select(x => new string[] {x.Name, x.PhoneNumber, x.Email }),
];
}
}
}

View File

@ -0,0 +1,313 @@
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using DocumentFormat.OpenXml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectPublishing.Reports
{
public class ExcelBuilder
{
private readonly string _filePath;
private readonly SheetData _sheetData;
private readonly MergeCells _mergeCells;
private readonly Columns _columns;
private uint _rowIndex = 0;
public ExcelBuilder(string filePath)
{
if (string.IsNullOrWhiteSpace(filePath)) throw new ArgumentNullException(nameof(filePath));
if (File.Exists(filePath)) File.Delete(filePath);
_filePath = filePath;
_sheetData = new SheetData();
_mergeCells = new MergeCells();
_columns = new Columns();
_rowIndex = 1;
}
public ExcelBuilder AddHeader(string header, int startIndex, int count)
{
CreateCell(startIndex, _rowIndex, header, StyleIndex.BoldTextWithoutBorder);
for (int i = startIndex + 1; i < startIndex + count; ++i)
{
CreateCell(i, _rowIndex, "", StyleIndex.SimpleTextWithoutBorder);
}
_mergeCells.Append(new MergeCell()
{
Reference = new StringValue($"{GetExcelColumnName(startIndex)}{_rowIndex}:{GetExcelColumnName(startIndex + count - 1)}{_rowIndex}")
});
_rowIndex++;
return this;
}
public ExcelBuilder AddParagraph(string text, int columnIndex)
{
CreateCell(columnIndex, _rowIndex++, text, StyleIndex.SimpleTextWithoutBorder);
return this;
}
public ExcelBuilder AddTable(int[] columnsWidths, List<string[]> data)
{
if (columnsWidths == null || columnsWidths.Length == 0) throw new ArgumentNullException(nameof(columnsWidths));
if (data == null || data.Count == 0) throw new ArgumentNullException(nameof(data));
if (data.Any(x => x.Length != columnsWidths.Length)) throw new InvalidOperationException("widths.Length != data.Length");
uint counter = 1;
int coef = 2;
_columns.Append(columnsWidths.Select(x => new Column
{
Min = counter,
Max = counter++,
Width = x * coef,
CustomWidth = true
}));
for (var j = 0; j < data.First().Length; ++j)
{
CreateCell(j, _rowIndex, data.First()[j], StyleIndex.BoldTextWithBorder);
}
_rowIndex++;
for (var i = 1; i < data.Count - 1; ++i)
{
for (var j = 0; j < data[i].Length; ++j)
{
CreateCell(j, _rowIndex, data[i][j], StyleIndex.SimpleTextWithBorder);
}
_rowIndex++;
}
for (var j = 0; j < data.Last().Length; ++j)
{
CreateCell(j, _rowIndex, data.Last()[j], StyleIndex.BoldTextWithBorder);
}
_rowIndex++;
return this;
}
public void Build()
{
using var spreadsheetDocument = SpreadsheetDocument.Create(_filePath, SpreadsheetDocumentType.Workbook);
var workbookpart = spreadsheetDocument.AddWorkbookPart();
GenerateStyle(workbookpart);
workbookpart.Workbook = new Workbook();
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet();
if (_columns.HasChildren)
{
worksheetPart.Worksheet.Append(_columns);
}
worksheetPart.Worksheet.Append(_sheetData);
var sheets = spreadsheetDocument.WorkbookPart!.Workbook.AppendChild(new Sheets());
var sheet = new Sheet()
{
Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart),
SheetId = 1,
Name = "Лист 1"
};
sheets.Append(sheet);
if (_mergeCells.HasChildren)
{
worksheetPart.Worksheet.InsertAfter(_mergeCells,
worksheetPart.Worksheet.Elements<SheetData>().First());
}
}
private static void GenerateStyle(WorkbookPart workbookPart)
{
var workbookStylesPart = workbookPart.AddNewPart<WorkbookStylesPart>();
workbookStylesPart.Stylesheet = new Stylesheet();
var fonts = new Fonts() { Count = 2, KnownFonts = BooleanValue.FromBoolean(true) };
fonts.Append(new DocumentFormat.OpenXml.Spreadsheet.Font
{
FontSize = new FontSize() { Val = 11 },
FontName = new FontName() { Val = "Calibri" },
FontFamilyNumbering = new FontFamilyNumbering() { Val = 2 },
FontScheme = new FontScheme() { Val = new EnumValue<FontSchemeValues>(FontSchemeValues.Minor) }
});
fonts.Append(new DocumentFormat.OpenXml.Spreadsheet.Font
{
FontSize = new FontSize() { Val = 11 },
FontName = new FontName() { Val = "Calibri" },
FontFamilyNumbering = new FontFamilyNumbering() { Val = 2 },
FontScheme = new FontScheme() { Val = new EnumValue<FontSchemeValues>(FontSchemeValues.Minor) },
Bold = new Bold() { Val = true }
});
workbookStylesPart.Stylesheet.Append(fonts);
var fills = new Fills() { Count = 1 };
fills.Append(new Fill
{
PatternFill = new PatternFill() { PatternType = new EnumValue<PatternValues>(PatternValues.None) }
});
workbookStylesPart.Stylesheet.Append(fills);
var borders = new Borders() { Count = 2 };
borders.Append(new Border
{
LeftBorder = new LeftBorder(),
RightBorder = new RightBorder(),
TopBorder = new TopBorder(),
BottomBorder = new BottomBorder(),
DiagonalBorder = new DiagonalBorder()
});
borders.Append(new Border
{
LeftBorder = new LeftBorder() { Style = BorderStyleValues.Thin },
RightBorder = new RightBorder() { Style = BorderStyleValues.Thin },
TopBorder = new TopBorder() { Style = BorderStyleValues.Thin },
BottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin },
DiagonalBorder = new DiagonalBorder()
});
workbookStylesPart.Stylesheet.Append(borders);
var cellFormats = new CellFormats() { Count = 4 };
cellFormats.Append(new CellFormat
{
NumberFormatId = 0,
FormatId = 0,
FontId = 0,
BorderId = 0,
FillId = 0,
Alignment = new Alignment()
{
Horizontal = HorizontalAlignmentValues.Left,
Vertical = VerticalAlignmentValues.Center,
WrapText = true
}
});
cellFormats.Append(new CellFormat
{
NumberFormatId = 0,
FormatId = 0,
FontId = 0,
BorderId = 1,
FillId = 0,
Alignment = new Alignment()
{
Horizontal = HorizontalAlignmentValues.Right,
Vertical = VerticalAlignmentValues.Center,
WrapText = true
}
});
cellFormats.Append(new CellFormat
{
NumberFormatId = 0,
FormatId = 0,
FontId = 1,
BorderId = 0,
FillId = 0,
Alignment = new Alignment()
{
Horizontal = HorizontalAlignmentValues.Center,
Vertical = VerticalAlignmentValues.Center,
WrapText = true
}
});
cellFormats.Append(new CellFormat
{
NumberFormatId = 0,
FormatId = 0,
FontId = 1,
BorderId = 1,
FillId = 0,
Alignment = new Alignment()
{
Horizontal = HorizontalAlignmentValues.Center,
Vertical = VerticalAlignmentValues.Center,
WrapText = true
}
});
workbookStylesPart.Stylesheet.Append(cellFormats);
}
private enum StyleIndex
{
SimpleTextWithoutBorder = 0,
SimpleTextWithBorder = 1,
BoldTextWithoutBorder = 2,
BoldTextWithBorder = 3,
}
private void CreateCell(int columnIndex, uint rowIndex, string text, StyleIndex styleIndex)
{
var columnName = GetExcelColumnName(columnIndex);
var cellReference = columnName + rowIndex;
var row = _sheetData.Elements<Row>().FirstOrDefault(r => r.RowIndex! == rowIndex);
if (row == null)
{
row = new Row() { RowIndex = rowIndex };
_sheetData.Append(row);
}
var newCell = row.Elements<Cell>().FirstOrDefault(c => c.CellReference != null && c.CellReference.Value == columnName + rowIndex);
if (newCell == null)
{
Cell? refCell = null;
foreach (Cell cell in row.Elements<Cell>())
{
if (cell.CellReference?.Value != null && cell.CellReference.Value.Length == cellReference.Length)
{
if (string.Compare(cell.CellReference.Value, cellReference, true) > 0)
{
refCell = cell;
break;
}
}
}
newCell = new Cell() { CellReference = cellReference };
row.InsertBefore(newCell, refCell);
}
newCell.CellValue = new CellValue(text);
newCell.DataType = CellValues.String;
newCell.StyleIndex = (uint)styleIndex;
}
private static string GetExcelColumnName(int columnNumber)
{
columnNumber += 1;
int dividend = columnNumber;
string columnName = string.Empty;
int modulo;
while (dividend > 0)
{
modulo = (dividend - 1) % 26;
columnName = Convert.ToChar(65 + modulo).ToString() + columnName;
dividend = (dividend - modulo) / 26;
}
return columnName;
}
}
}

View File

@ -0,0 +1,86 @@
using Microsoft.Extensions.Logging;
using ProjectPublishing.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectPublishing.Reports
{
public class TableReport
{
private readonly IOrderRepository _orderRepository;
private readonly IMaterialAdmissionRepository _materialAdmissionRepository;
private readonly ILogger<TableReport> _logger;
internal static readonly string[] item = ["Материал", "Дата", "Количество поступило", "Количество заказано"];
public TableReport(IOrderRepository orderRepository, IMaterialAdmissionRepository materialAdmissionRepository, ILogger<TableReport> logger)
{
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
_materialAdmissionRepository = materialAdmissionRepository ?? throw new ArgumentNullException(nameof(materialAdmissionRepository));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
public bool CreateTable(string filePath, int materialId, DateTime startDate, DateTime endDate)
{
try
{
new ExcelBuilder(filePath)
.AddHeader("Сводка по материалам", 0, 4)
.AddParagraph($"за период с {startDate:dd.MM.yyyy} по {endDate:dd.MM.yyyy}", 0)
.AddTable([15, 15, 15, 15], GetData(materialId, startDate, endDate))
.Build();
return true;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при формировании документа");
return false;
}
}
private List<string[]> GetData(int materialId, DateTime startDate, DateTime endDate)
{
var data = _materialAdmissionRepository
.ReadMaterialsAdmission()
.Where(x => x.DateTime >= startDate && x.DateTime <= endDate && x.MaterialId == materialId)
.Select(x => new {
MaterialId = x.MaterialId,
Date = x.DateTime,
CountIn = (int?)x.Amount,
CountOut = (int?)null
})
.Union(
_orderRepository
.ReadOrders()
.Where(x => x.OrderDate >= startDate && x.OrderDate <= endDate && x.Materials.Any(y => y.MaterialsId == materialId))
.SelectMany(order => order.Materials
.Where(m => m.MaterialsId == materialId)
.Select(m => new {
MaterialId = m.MaterialsId,
Date = order.OrderDate,
CountIn = (int?)null,
CountOut = (int?)m.Amount
})))
.OrderBy(x => x.Date);
return new List<string[]> { item }
.Union(
data.Select(x => new string[] {
x.MaterialId.ToString(),
x.Date.ToString("dd.MM.yyyy"),
x.CountIn?.ToString() ?? string.Empty,
x.CountOut?.ToString() ?? string.Empty
}))
.Union(new[] {
new string[] {
"Всего",
string.Empty,
data.Sum(x => x.CountIn ?? 0).ToString(),
data.Sum(x => x.CountOut ?? 0).ToString()
}
})
.ToList();
}
}
}

View File

@ -0,0 +1,98 @@
using DocumentFormat.OpenXml.Drawing.Charts;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Wordprocessing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DocumentFormat.OpenXml.Packaging;
namespace ProjectPublishing.Reports
{
public class WordBuilder
{
private readonly string _filePath;
private readonly Document _document;
private readonly Body _body;
public WordBuilder(string filePath)
{
if (string.IsNullOrWhiteSpace(filePath)) throw new ArgumentNullException(nameof(filePath));
if (File.Exists(filePath)) File.Delete(filePath);
_filePath = filePath;
_document = new Document();
_body = _document.AppendChild(new Body());
}
public WordBuilder AddHeader(string header)
{
var paragraph = _body.AppendChild(new Paragraph());
var run = paragraph.AppendChild(new Run());
var runProperties = run.AppendChild(new RunProperties());
runProperties.AppendChild(new Bold());
run.AppendChild(new Text(header));
return this;
}
public WordBuilder AddParagraph(string text)
{
var paragraph = _body.AppendChild(new Paragraph());
var run = paragraph.AppendChild(new Run());
run.AppendChild(new Text(text));
return this;
}
public WordBuilder AddTable(int[] widths, List<string[]> data)
{
if (widths == null || widths.Length == 0)
throw new ArgumentNullException(nameof(widths));
if (data == null || data.Count == 0)
throw new ArgumentNullException(nameof(data));
if (data.Any(x => x.Length != widths.Length))
throw new InvalidOperationException("widths.Length != data.Length");
var table = new Table();
table.AppendChild(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 })));
var tr = new TableRow();
for (var j = 0; j < widths.Length; ++j)
{
tr.Append(new TableCell(
new TableCellProperties(new TableCellWidth() { Width = widths[j].ToString() }),
new Paragraph(new Run(new RunProperties(new Bold()), new Text(data.First()[j])))));
}
table.Append(tr);
table.Append(data.Skip(1).Select(x => new TableRow(x.Select(y => new TableCell(new Paragraph(new Run(new Text(y))))))));
_body.Append(table);
return this;
}
public void Build()
{
using var wordDocument = WordprocessingDocument.Create(_filePath, WordprocessingDocumentType.Document);
var mainPart = wordDocument.AddMainDocumentPart();
mainPart.Document = _document;
}
}
}