diff --git a/UserComponentsOption19/TestAppForCheckComponentsWorking/FormTestNoVisibleComponents.Designer.cs b/UserComponentsOption19/TestAppForCheckComponentsWorking/FormTestNoVisibleComponents.Designer.cs new file mode 100644 index 0000000..c60137a --- /dev/null +++ b/UserComponentsOption19/TestAppForCheckComponentsWorking/FormTestNoVisibleComponents.Designer.cs @@ -0,0 +1,62 @@ +namespace TestAppForCheckComponentsWorking +{ + partial class FormTestNoVisibleComponents + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + 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; + } +} \ No newline at end of file diff --git a/UserComponentsOption19/TestAppForCheckComponentsWorking/FormTestNoVisibleComponents.cs b/UserComponentsOption19/TestAppForCheckComponentsWorking/FormTestNoVisibleComponents.cs new file mode 100644 index 0000000..247b8e2 --- /dev/null +++ b/UserComponentsOption19/TestAppForCheckComponentsWorking/FormTestNoVisibleComponents.cs @@ -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); + } + } + } + } +} diff --git a/UserComponentsOption19/TestAppForCheckComponentsWorking/FormTestNoVisibleComponents.resx b/UserComponentsOption19/TestAppForCheckComponentsWorking/FormTestNoVisibleComponents.resx new file mode 100644 index 0000000..3c35fa1 --- /dev/null +++ b/UserComponentsOption19/TestAppForCheckComponentsWorking/FormTestNoVisibleComponents.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/UserComponentsOption19/TestAppForCheckComponentsWorking/Form1.Designer.cs b/UserComponentsOption19/TestAppForCheckComponentsWorking/FormTestVisibleComponents.Designer.cs similarity index 100% rename from UserComponentsOption19/TestAppForCheckComponentsWorking/Form1.Designer.cs rename to UserComponentsOption19/TestAppForCheckComponentsWorking/FormTestVisibleComponents.Designer.cs diff --git a/UserComponentsOption19/TestAppForCheckComponentsWorking/Form1.cs b/UserComponentsOption19/TestAppForCheckComponentsWorking/FormTestVisibleComponents.cs similarity index 100% rename from UserComponentsOption19/TestAppForCheckComponentsWorking/Form1.cs rename to UserComponentsOption19/TestAppForCheckComponentsWorking/FormTestVisibleComponents.cs diff --git a/UserComponentsOption19/TestAppForCheckComponentsWorking/Form1.resx b/UserComponentsOption19/TestAppForCheckComponentsWorking/FormTestVisibleComponents.resx similarity index 100% rename from UserComponentsOption19/TestAppForCheckComponentsWorking/Form1.resx rename to UserComponentsOption19/TestAppForCheckComponentsWorking/FormTestVisibleComponents.resx diff --git a/UserComponentsOption19/TestAppForCheckComponentsWorking/Program.cs b/UserComponentsOption19/TestAppForCheckComponentsWorking/Program.cs index f2ad505..cfb034b 100644 --- a/UserComponentsOption19/TestAppForCheckComponentsWorking/Program.cs +++ b/UserComponentsOption19/TestAppForCheckComponentsWorking/Program.cs @@ -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()); } } } \ No newline at end of file diff --git a/UserComponentsOption19/UserComponentsOption19/BigTextWordNoVisibleComponent.Designer.cs b/UserComponentsOption19/UserComponentsOption19/BigTextWordNoVisibleComponent.Designer.cs new file mode 100644 index 0000000..4db485e --- /dev/null +++ b/UserComponentsOption19/UserComponentsOption19/BigTextWordNoVisibleComponent.Designer.cs @@ -0,0 +1,36 @@ +namespace UserComponentsOption19 +{ + partial class BigTextWordNoVisibleComponent + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} diff --git a/UserComponentsOption19/UserComponentsOption19/BigTextWordNoVisibleComponent.cs b/UserComponentsOption19/UserComponentsOption19/BigTextWordNoVisibleComponent.cs new file mode 100644 index 0000000..9eed55d --- /dev/null +++ b/UserComponentsOption19/UserComponentsOption19/BigTextWordNoVisibleComponent.cs @@ -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(); + } + } + } +} diff --git a/UserComponentsOption19/UserComponentsOption19/UserComponentsOption19.csproj b/UserComponentsOption19/UserComponentsOption19/UserComponentsOption19.csproj index 3e210aa..67a51a3 100644 --- a/UserComponentsOption19/UserComponentsOption19/UserComponentsOption19.csproj +++ b/UserComponentsOption19/UserComponentsOption19/UserComponentsOption19.csproj @@ -7,4 +7,8 @@ enable + + + +