PIbd-32_Shabunov_O.A._COP/ShabComponentsLibrary/ShabDocumentContextComponent.cs

66 lines
1.6 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 ShabComponentsLibrary.OfficePackage;
using ShabComponentsLibrary.OfficePackage.HelperEnums;
using ShabComponentsLibrary.OfficePackage.HelperModels;
using System.ComponentModel;
namespace ShabComponentsLibrary
{
/// <summary>
/// Невизуальный компонент для создания документа с таблицами
/// </summary>
public partial class ShabDocumentContextComponent : Component
{
public ShabDocumentContextComponent()
{
InitializeComponent();
}
public ShabDocumentContextComponent(IContainer Container)
{
Container.Add(this);
InitializeComponent();
}
public void CreateDocument(string Filename, string Title, List<string[][]> 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(3.0, 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);
}
}
}