52 lines
1.4 KiB
C#
52 lines
1.4 KiB
C#
|
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(); // Сохраняем изменения в документе
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|