фикс чтобы не обязательно все свойства писать

КОМАНДНАЯ РАБОТА
This commit is contained in:
frog24 2024-10-22 16:33:42 +04:00
parent afd75a94eb
commit cefc5fcbe3
2 changed files with 17 additions and 16 deletions

View File

@ -115,30 +115,31 @@ namespace BarsukovComponents.NotVisualComponents
foreach (var item in data)
{
var properties = item.GetType().GetProperties();
if (properties.Count() != cellsCount)
{
throw new Exception("Кол-во полей объекта не совпадает с кол-вом колонок");
}
//if (properties.Count() != cellsCount)
//{
// throw new Exception("Кол-во полей объекта не совпадает с кол-вом колонок");
//}
for (int i = 0; i < properties.Count(); i++)
for (int i = 0; i < cellsCount; i++)
{
var property = properties[i];
var propValue = property.GetValue(item);
if (propValue == null)
{
throw new Exception("Пустое поле");
}
if (property.Name == colInfo[i].PropertyName)
var property = properties.FirstOrDefault(p => p.Name == colInfo[i].PropertyName);
if (property != null)
{
var propValue = property.GetValue(item);
if (propValue == null)
{
throw new Exception("Пустое поле");
}
if (table.Rows.Count <= rowData)
{
table.AddRow();
}
table.Rows[rowData].Cells[i].AddParagraph(propValue.ToString());
continue;
}
}
rowData++;
}
var renderer = new PdfDocumentRenderer(true);

View File

@ -115,13 +115,13 @@ namespace TestApp
{
new ColumnInfo("First","First Prop",50),
new ColumnInfo("Second","Second Prop",100),
new ColumnInfo("Third","Third Prop",100),
//new ColumnInfo("Third","Third Prop",100),
new ColumnInfo("Fourth","Fourth Prop",200),
new ColumnInfo("Fifth","Fifth Prop",50),
};
List<MergeCells> mergeCells = new List<MergeCells>()
{
new MergeCells("Merged columns", new int[] {3,4})
new MergeCells("Merged columns", new int[] {2,3})
};
List<Example> workers = new List<Example>()
{