Compare commits
2 Commits
a90c2b2cde
...
6c1b361fef
Author | SHA1 | Date | |
---|---|---|---|
6c1b361fef | |||
a69a7fa17d |
@ -1,3 +1,4 @@
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using ShabComponentsLibrary;
|
||||
using ShabComponentsLibrary.Exceptions;
|
||||
|
||||
@ -132,12 +133,15 @@ namespace FormsTesting
|
||||
};
|
||||
|
||||
ConfigurableTableComponent.CreateDocument(
|
||||
@"C:\Comps\Doc2.pdf",
|
||||
"Íàñòðàèâàåìàÿ òàáëèöà",
|
||||
new List<string> { "3cm", "2cm", "3cm", "4cm" },
|
||||
new List<string> { "1cm", "0.6cm" },
|
||||
new List<string> { "Ôàìèëèÿ", "Èäåíò.", "Èìÿ", "Âîçðàñò" },
|
||||
new List<string> { "LastName", "Id", "FirstName", "Age" },
|
||||
@"C:\Comps\Doc2.pdf", "Íŕńňđŕčâŕĺěŕ˙ ňŕáëčöŕ",
|
||||
new List<(double, string, string)>
|
||||
{
|
||||
(3.0, "Ôŕěčëč˙", "LastName"),
|
||||
(2.0, "Čäĺíň.", "Id"),
|
||||
(3.0, "Čě˙", "FirstName"),
|
||||
(4.0, "Âîçđŕńň", "Age"),
|
||||
},
|
||||
new List<double> { 1.0, 0.6 },
|
||||
Persons);
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,6 @@ namespace ShabComponentsLibrary.OfficePackage.HelperModels
|
||||
|
||||
public PdfParagraphAlignmentType? FirstCellParagraphAlignment { get; set; }
|
||||
|
||||
public string? RowHeight { get; set; }
|
||||
public double? RowHeight { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -56,15 +56,15 @@ namespace ShabComponentsLibrary.OfficePackage
|
||||
Paragraph.Style = PdfParagraph.Style;
|
||||
}
|
||||
|
||||
public void CreateTable(List<string> Columns)
|
||||
public void CreateTable(List<double> ColumnWidths)
|
||||
{
|
||||
if (_document == null)
|
||||
return;
|
||||
|
||||
_table = _document.LastSection.AddTable();
|
||||
foreach (var Column in Columns)
|
||||
foreach (var ColumnWidth in ColumnWidths)
|
||||
{
|
||||
_table.AddColumn(Column);
|
||||
_table.AddColumn(Unit.FromCentimeter(ColumnWidth));
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,7 +98,7 @@ namespace ShabComponentsLibrary.OfficePackage
|
||||
|
||||
if (RowParameters.RowHeight is not null)
|
||||
{
|
||||
Row.Height = RowParameters.RowHeight;
|
||||
Row.Height = Unit.FromCentimeter((double)RowParameters.RowHeight);
|
||||
}
|
||||
|
||||
Unit borderWidth = 0.5;
|
||||
@ -126,9 +126,6 @@ namespace ShabComponentsLibrary.OfficePackage
|
||||
series.Add(dataSeries.Value.Select(x => (double)x).ToArray());
|
||||
}
|
||||
|
||||
//var xseries = chart.XValues.AddXSeries();
|
||||
//xseries.Add(new string[] { "1", "2", "3" });
|
||||
|
||||
chart.TopArea.AddParagraph(ChartParameters.Title);
|
||||
|
||||
chart.XAxis.MajorTickMark = TickMarkType.Outside;
|
||||
|
@ -22,23 +22,20 @@ namespace ShabComponentsLibrary
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void CreateDocument<T>(string Filename, string Title, List<string> ColumnWidths, List<string> RowHeights,
|
||||
List<string> TableHeaders, List<string> HeaderPropertyNames, List<T> Data)
|
||||
public void CreateDocument<T>(string Filename, string Title,
|
||||
List<(double ColumnWidth, string TableHeader, string HeaderPropertyName)> ColumnData,
|
||||
List<double> RowHeights, List<T> Data)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Filename))
|
||||
throw new ArgumentException("Filename cannot be empty");
|
||||
if (string.IsNullOrEmpty(Title))
|
||||
throw new ArgumentException("Title cannot be empty");
|
||||
if (TableHeaders.Count == 0)
|
||||
if (ColumnData.Count == 0)
|
||||
throw new ArgumentException("Headers cannot be empty");
|
||||
if (Data.Count == 0)
|
||||
throw new ArgumentException("Data cannot be empty");
|
||||
if (ColumnWidths.Count != TableHeaders.Count)
|
||||
throw new ArgumentException("Column widths count must match headers count");
|
||||
if (RowHeights.Count != 2)
|
||||
throw new ArgumentException("Row heights should be specified for header row and other rows");
|
||||
if (HeaderPropertyNames.Count != TableHeaders.Count)
|
||||
throw new ArgumentException("Each column must have a corresponding property mapping");
|
||||
|
||||
SaveToPdf Pdf = new SaveToPdf();
|
||||
Pdf.CreatePdf();
|
||||
@ -49,12 +46,12 @@ namespace ShabComponentsLibrary
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||
});
|
||||
|
||||
Pdf.CreateTable(ColumnWidths);
|
||||
Pdf.CreateTable(ColumnData.Select(x => x.ColumnWidth).ToList());
|
||||
|
||||
// Шапка
|
||||
Pdf.CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = TableHeaders,
|
||||
Texts = ColumnData.Select(x => x.TableHeader).ToList(),
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Center,
|
||||
RowHeight = RowHeights[0]
|
||||
@ -65,9 +62,9 @@ namespace ShabComponentsLibrary
|
||||
{
|
||||
List<string> Cells = new List<string>();
|
||||
|
||||
for (int ColumnIndex = 0; ColumnIndex < TableHeaders.Count; ++ColumnIndex)
|
||||
for (int ColumnIndex = 0; ColumnIndex < ColumnData.Count; ++ColumnIndex)
|
||||
{
|
||||
string PropertyName = HeaderPropertyNames[ColumnIndex];
|
||||
string PropertyName = ColumnData[ColumnIndex].HeaderPropertyName;
|
||||
var Property = typeof(T).GetProperty(PropertyName);
|
||||
if (Property is null)
|
||||
{
|
||||
|
@ -46,7 +46,7 @@ namespace ShabComponentsLibrary
|
||||
continue;
|
||||
}
|
||||
|
||||
Pdf.CreateTable(Enumerable.Repeat("3cm", Table[0].Length).ToList());
|
||||
Pdf.CreateTable(Enumerable.Repeat(3.0, Table[0].Length).ToList());
|
||||
foreach (string[] Row in Table)
|
||||
{
|
||||
Pdf.CreateRow(new PdfRowParameters
|
||||
|
Loading…
Reference in New Issue
Block a user