66 lines
1.6 KiB
C#
66 lines
1.6 KiB
C#
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);
|
||
}
|
||
}
|
||
}
|