шапка вертикальная, а данные нет
This commit is contained in:
parent
a6a440e181
commit
31b37da456
@ -13,13 +13,13 @@ namespace Library14Petrushin
|
|||||||
public partial class PdfColGroupTable : Component
|
public partial class PdfColGroupTable : Component
|
||||||
{
|
{
|
||||||
public void GeneratePdf<T>(
|
public void GeneratePdf<T>(
|
||||||
string fileName,
|
string fileName,
|
||||||
string documentTitle,
|
string documentTitle,
|
||||||
List<(int startRow, int endRow, int startColumn, int endColumn)> mergeCells,
|
List<(int startRow, int endRow, int startColumn, int endColumn)> mergeCells,
|
||||||
List<double> rowHeights,
|
List<double> rowHeights,
|
||||||
List<string> headers,
|
List<string> headers,
|
||||||
List<string> propertyNames,
|
List<string> propertyNames,
|
||||||
List<T> data)
|
List<T> data)
|
||||||
{
|
{
|
||||||
// Проверка на заполненность входных данных
|
// Проверка на заполненность входных данных
|
||||||
if (string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(documentTitle) ||
|
if (string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(documentTitle) ||
|
||||||
@ -41,23 +41,6 @@ namespace Library14Petrushin
|
|||||||
throw new ArgumentException("Количество высот строк должно совпадать с количеством строк данных.");
|
throw new ArgumentException("Количество высот строк должно совпадать с количеством строк данных.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверка на наложение объединенных ячеек
|
|
||||||
foreach (var (startRow, endRow, startColumn, endColumn) in mergeCells)
|
|
||||||
{
|
|
||||||
foreach (var (otherStartRow, otherEndRow, otherStartColumn, otherEndColumn) in mergeCells)
|
|
||||||
{
|
|
||||||
if (startRow != otherStartRow || endRow != otherEndRow ||
|
|
||||||
startColumn != otherStartColumn || endColumn != otherEndColumn)
|
|
||||||
{
|
|
||||||
if (startRow <= otherEndRow && endRow >= otherStartRow &&
|
|
||||||
startColumn <= otherEndColumn && endColumn >= otherStartColumn)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Объединенные ячейки не должны накладываться друг на друга.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Создание документа
|
// Создание документа
|
||||||
PdfDocument document = new PdfDocument();
|
PdfDocument document = new PdfDocument();
|
||||||
PdfPage page = document.AddPage();
|
PdfPage page = document.AddPage();
|
||||||
@ -68,17 +51,20 @@ namespace Library14Petrushin
|
|||||||
gfx.DrawString(documentTitle, new XFont("Verdana", 16, XFontStyleEx.Bold), XBrushes.Black, new XRect(0, 0, page.Width, 50), XStringFormats.Center);
|
gfx.DrawString(documentTitle, new XFont("Verdana", 16, XFontStyleEx.Bold), XBrushes.Black, new XRect(0, 0, page.Width, 50), XStringFormats.Center);
|
||||||
|
|
||||||
// Отрисовка таблицы
|
// Отрисовка таблицы
|
||||||
double x = 50;
|
double margin = 50; // Отступ от краев страницы
|
||||||
|
double x = margin;
|
||||||
double y = 70;
|
double y = 70;
|
||||||
double columnWidth = (page.Width - 100) / headers.Count;
|
double rowHeight = 20; // Фиксированная высота строки
|
||||||
|
double columnWidth = (page.Width - 2 * margin) / (headers.Count + 1); // Ширина столбца
|
||||||
|
|
||||||
// Отрисовка заголовков
|
// Отрисовка шапки
|
||||||
for (int i = 0; i < headers.Count; i++)
|
for (int col = 0; col < headers.Count; col++)
|
||||||
{
|
{
|
||||||
gfx.DrawString(headers[i], font, XBrushes.Black, new XRect(x + i * columnWidth, y, columnWidth, rowHeights[0]), XStringFormats.CenterLeft);
|
gfx.DrawString(headers[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)); // Добавляем рамку
|
||||||
}
|
}
|
||||||
|
|
||||||
y += rowHeights[0];
|
x += columnWidth;
|
||||||
|
|
||||||
// Отрисовка данных
|
// Отрисовка данных
|
||||||
for (int row = 0; row < data.Count; row++)
|
for (int row = 0; row < data.Count; row++)
|
||||||
@ -90,22 +76,22 @@ namespace Library14Petrushin
|
|||||||
if (property != null)
|
if (property != null)
|
||||||
{
|
{
|
||||||
var value = property.GetValue(item)?.ToString() ?? string.Empty;
|
var value = property.GetValue(item)?.ToString() ?? string.Empty;
|
||||||
gfx.DrawString(value, font, XBrushes.Black, new XRect(x + col * columnWidth, y, columnWidth, rowHeights[row]), XStringFormats.CenterLeft);
|
gfx.DrawString(value, font, XBrushes.Black, new XRect(x + col * columnWidth, y + row * rowHeight, columnWidth, rowHeight), XStringFormats.CenterLeft);
|
||||||
|
gfx.DrawRectangle(XPens.Black, new XRect(x + col * columnWidth, y + row * rowHeight, columnWidth, rowHeight)); // Добавляем рамку
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
y += rowHeights[row];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Объединение ячеек
|
// Объединение ячеек
|
||||||
foreach (var (startRow, endRow, startColumn, endColumn) in mergeCells)
|
foreach (var (startRow, endRow, startColumn, endColumn) in mergeCells)
|
||||||
{
|
{
|
||||||
double mergeY = 70 + (startRow * rowHeights[startRow]);
|
double mergeX = margin + (startColumn * columnWidth);
|
||||||
double mergeHeight = (endRow - startRow + 1) * rowHeights[startRow];
|
|
||||||
double mergeX = 50 + (startColumn * columnWidth);
|
|
||||||
double mergeWidth = (endColumn - startColumn + 1) * columnWidth;
|
double mergeWidth = (endColumn - startColumn + 1) * columnWidth;
|
||||||
|
double mergeY = 70 + (startRow * rowHeight);
|
||||||
|
double mergeHeight = (endRow - startRow + 1) * rowHeight;
|
||||||
|
|
||||||
gfx.DrawRectangle(XPens.Black, XBrushes.White, new XRect(mergeX, mergeY, mergeWidth, mergeHeight));
|
gfx.DrawRectangle(XPens.Black, XBrushes.White, new XRect(mergeX, mergeY, mergeWidth, mergeHeight));
|
||||||
gfx.DrawString(headers[startColumn], font, XBrushes.Black, new XRect(mergeX, mergeY, mergeWidth, mergeHeight), XStringFormats.Center);
|
gfx.DrawString(headers[startRow], font, XBrushes.Black, new XRect(mergeX, mergeY, mergeWidth, mergeHeight), XStringFormats.Center);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Сохранение документа
|
// Сохранение документа
|
||||||
|
Loading…
x
Reference in New Issue
Block a user