2024-09-24 23:54:36 +04:00
|
|
|
|
using ShabComponentsLibrary.OfficePackage;
|
2024-09-24 19:20:38 +04:00
|
|
|
|
using ShabComponentsLibrary.OfficePackage.HelperEnums;
|
|
|
|
|
using ShabComponentsLibrary.OfficePackage.HelperModels;
|
2024-09-24 23:54:36 +04:00
|
|
|
|
using System.ComponentModel;
|
2024-09-24 19:20:38 +04:00
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2024-09-25 00:46:40 +04:00
|
|
|
|
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");
|
|
|
|
|
|
2024-09-24 19:20:38 +04:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-09 15:45:39 +04:00
|
|
|
|
Pdf.CreateTable(Enumerable.Repeat(3.0, Table[0].Length).ToList());
|
2024-09-24 19:20:38 +04:00
|
|
|
|
foreach (string[] Row in Table)
|
|
|
|
|
{
|
|
|
|
|
Pdf.CreateRow(new PdfRowParameters
|
|
|
|
|
{
|
|
|
|
|
Texts = Row.ToList(),
|
|
|
|
|
Style = "Normal",
|
2024-09-24 23:54:36 +04:00
|
|
|
|
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
2024-09-24 19:20:38 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
Pdf.CreateParagraph(new PdfParagraph());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Pdf.SavePdf(Filename);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|