Compare commits

...

2 Commits

Author SHA1 Message Date
GokaPek
c17a7faddc две колонки хедеров 2024-09-30 10:56:46 +04:00
GokaPek
fc113983ea получилось! 2024-09-30 00:41:41 +04:00
2 changed files with 18 additions and 7 deletions

View File

@ -87,14 +87,15 @@ namespace ExexForm2
};
var headers = new List<string> { "First Name", "Last Name", "Age" };
var commonHeaders = new List<string> { "Name", "", "" };
var propertyNames = new List<string> { "FirstName", "LastName", "Age" };
var rowHeights = new List<double> { 20, 20 };
var mergeCells = new List<(int startRow, int endRow, int startColumn, int endColumn)>
{
(0, 0, 0, 1) // Îáúåäèíåíèå ïåðâûõ äâóõ ñòîëáöîâ â ïåðâîé ñòðîêå
(0, 1, 0, 0) // 0 è 1 ÿ÷åéêè ïî âåðòèêàëè ïåðâîé êîëîíêè
};
generator.GeneratePdf(fileName, "Example Document", mergeCells, rowHeights, headers, propertyNames, data1);
generator.GeneratePdf(fileName, "Example Document", mergeCells, rowHeights, headers, commonHeaders, propertyNames, data1);
}
}
}

View File

@ -18,6 +18,7 @@ namespace Library14Petrushin
List<(int startRow, int endRow, int startColumn, int endColumn)> mergeCells,
List<double> rowHeights,
List<string> headers,
List<string> commonHeaders,
List<string> propertyNames,
List<T> data)
{
@ -58,6 +59,15 @@ namespace Library14Petrushin
double columnWidth = (page.Width - 2 * margin) / (headers.Count + 1); // Ширина столбца
// Отрисовка шапки
for (int col = 0; col < commonHeaders.Count; col++)
{
gfx.DrawString(commonHeaders[col], font, XBrushes.Black, new XRect(x, y + col * rowHeight, columnWidth, rowHeight), XStringFormats.CenterLeft);
gfx.DrawRectangle(XPens.Black, new XRect(x, y + col * rowHeight, columnWidth, rowHeight)); // Добавляем рамку
}
x += columnWidth;
for (int col = 0; col < headers.Count; col++)
{
gfx.DrawString(headers[col], font, XBrushes.Black, new XRect(x, y + col * rowHeight, columnWidth, rowHeight), XStringFormats.CenterLeft);
@ -67,12 +77,12 @@ namespace Library14Petrushin
x += columnWidth;
// Отрисовка данных
for (int row = 0; row < data.Count; row++)
for (int col = 0; col < data.Count; col++)
{
var item = data[row];
for (int col = 0; col < propertyNames.Count; col++)
for (int row = 0; row < propertyNames.Count; row++)
{
var property = item.GetType().GetProperty(propertyNames[col]);
var item = data[col];
var property = item.GetType().GetProperty(propertyNames[row]);
if (property != null)
{
var value = property.GetValue(item)?.ToString() ?? string.Empty;