using ShabComponentsLibrary.OfficePackage; using ShabComponentsLibrary.OfficePackage.HelperEnums; using ShabComponentsLibrary.OfficePackage.HelperModels; using System.ComponentModel; namespace ShabComponentsLibrary { /// /// Невизуальный компонент для создания документа с таблицами /// public partial class ShabDocumentContextComponent : Component { public ShabDocumentContextComponent() { InitializeComponent(); } public ShabDocumentContextComponent(IContainer Container) { Container.Add(this); InitializeComponent(); } public void CreateDocument(string Filename, string Title, List Tables) { if (string.IsNullOrEmpty(Filename)) throw new ArgumentException("Filename cannot be empty"); if (string.IsNullOrEmpty(Title)) throw new ArgumentException("Title cannot be empty"); if (Tables.Count == 0) throw new ArgumentException("Data cannot be empty"); SaveToPdf Pdf = new SaveToPdf(); Pdf.CreatePdf(); Pdf.CreateParagraph(new PdfParagraph { Text = Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Left }); foreach (string[][] Table in Tables) { if (Table.Length == 0) { continue; } Pdf.CreateTable(Enumerable.Repeat("3cm", Table[0].Length).ToList()); foreach (string[] Row in Table) { Pdf.CreateRow(new PdfRowParameters { Texts = Row.ToList(), Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Left }); } Pdf.CreateParagraph(new PdfParagraph()); } Pdf.SavePdf(Filename); } } }