готов первый компонент

This commit is contained in:
Елена Бакальская 2024-10-06 22:24:58 +04:00
parent d79cf20111
commit 719ba80758
10 changed files with 321 additions and 1 deletions

View File

@ -0,0 +1,62 @@
namespace TestAppForCheckComponentsWorking
{
partial class FormTestNoVisibleComponents
{
/// <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();
buttonSaveBigTextToWord = new Button();
bigTextWordNoVisibleComponent = new UserComponentsOption19.BigTextWordNoVisibleComponent(components);
SuspendLayout();
//
// buttonSaveBigTextToWord
//
buttonSaveBigTextToWord.Location = new Point(12, 21);
buttonSaveBigTextToWord.Name = "buttonSaveBigTextToWord";
buttonSaveBigTextToWord.Size = new Size(270, 29);
buttonSaveBigTextToWord.TabIndex = 0;
buttonSaveBigTextToWord.Text = "Сохранить большой текст в ворд :)";
buttonSaveBigTextToWord.UseVisualStyleBackColor = true;
buttonSaveBigTextToWord.Click += buttonSaveBigTextToWord_Click;
//
// FormTestNoVisibleComponents
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(433, 383);
Controls.Add(buttonSaveBigTextToWord);
Name = "FormTestNoVisibleComponents";
Text = "FormTestNoVisibleComponents";
ResumeLayout(false);
}
#endregion
private Button buttonSaveBigTextToWord;
private UserComponentsOption19.BigTextWordNoVisibleComponent bigTextWordNoVisibleComponent;
}
}

View File

@ -0,0 +1,34 @@
namespace TestAppForCheckComponentsWorking
{
public partial class FormTestNoVisibleComponents : Form
{
public FormTestNoVisibleComponents()
{
InitializeComponent();
}
private void buttonSaveBigTextToWord_Click(object sender, EventArgs e)
{
//string fileName = OpenFileDialog.
//bigTextWordNoVisibleComponent.CreateAndSaveDocument();
using (SaveFileDialog saveFileDialog = new SaveFileDialog())
{
saveFileDialog.Filter = "Word Documents (*.docx)|*.docx";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
string filePath = saveFileDialog.FileName;
string title = "ХОБА давай знакомиться! :D"; // Замените на нужный заголовок
string[] data = { "Привет, я САня", "НЕт... это я Саня..", "чЮваки... будьте спокойнее _~_" }; // Пример массива строк
// Вызываем метод компонента для создания и сохранения документа
bigTextWordNoVisibleComponent.CreateAndSaveDocument(filePath, title, data);
}
}
}
}
}

View File

@ -0,0 +1,123 @@
<?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>
<metadata name="bigTextWordNoVisibleComponent.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -11,7 +11,7 @@ namespace TestAppForCheckComponentsWorking
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormTest());
Application.Run(new FormTestNoVisibleComponents());
}
}
}

View File

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

View File

@ -0,0 +1,61 @@
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using System.ComponentModel;
// КОМПОНЕНТ С БОЛЬШИМ... ТЕКСТОМ
namespace UserComponentsOption19
{
public partial class BigTextWordNoVisibleComponent : Component
{
private WordprocessingDocument? _wordDocument;
private Body? _docBody;
public BigTextWordNoVisibleComponent()
{
InitializeComponent();
}
public BigTextWordNoVisibleComponent(IContainer container) : this()
{
container.Add(this);
}
public void CreateAndSaveDocument(string filePath, string title, string[] data)
{
if (string.IsNullOrEmpty(filePath))
{
throw new ArgumentNullException(nameof(filePath), "Укажите путь к файлу :_3");
}
if (string.IsNullOrEmpty(title))
{
throw new ArgumentNullException(nameof(title), "Заголовок документа не заполнен...");
}
if (data == null || data.Length == 0)
{
throw new ArgumentNullException(nameof(data), "Массив строк где, Алеша? >:/");
}
using (_wordDocument = WordprocessingDocument.Create(filePath, WordprocessingDocumentType.Document))
{
var mainPart = _wordDocument.AddMainDocumentPart();
mainPart.Document = new Document();
_docBody = mainPart.Document.AppendChild(new Body());
var titleParagraph = new Paragraph(new Run(new Text(title)));
titleParagraph.ParagraphProperties = new ParagraphProperties(
new Justification() { Val = JustificationValues.Center },
new Bold());
_docBody.AppendChild(titleParagraph);
_docBody.AppendChild(new Paragraph());
foreach (var paragraphText in data)
{
var paragraph = new Paragraph(new Run(new Text(paragraphText)));
_docBody.AppendChild(paragraph);
}
mainPart.Document.Save();
}
}
}
}

View File

@ -7,4 +7,8 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="3.1.0" />
</ItemGroup>
</Project>