KOP-PIbd-32-Katysheva-N-E/ComponentsLibrary/ComponentBigText.cs
2024-09-30 22:43:40 +04:00

52 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using ComponentsView;
using DocumentFormat.OpenXml.Packaging;
using System.ComponentModel;
using System.Reflection.Metadata;
using static System.Net.Mime.MediaTypeNames;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
namespace ComponentsLibrary
{
public partial class ComponentBigText : Component
{
public ComponentBigText()
{
InitializeComponent();
}
public ComponentBigText(IContainer container)
{
container.Add(this);
InitializeComponent();
}
//публичный метод
public void SetText(string fileUrl, string fileName, string[] text)
{
// Создаем новый документ Word и сохраняем его по указанному пути
using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(Path.Combine(fileUrl, fileName), WordprocessingDocumentType.Document))
{
// Добавляем главный документ
MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();
mainPart.Document = new Document();
Body body = new Body();
// Добавляем текст в документ
foreach (var line in text)
{
Paragraph paragraph = new Paragraph(new Run(new Text(line)));
body.Append(paragraph);
}
// Заключаем тело документа
mainPart.Document.Append(body);
mainPart.Document.Save(); // Сохраняем изменения в документе
}
}
}
}