Files
QuestPDF/QuestPDF.Examples/TableExamples.cs
T

98 lines
3.6 KiB
C#
Raw Normal View History

2021-12-19 05:11:23 +01:00
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
2021-12-19 05:11:23 +01:00
using NUnit.Framework;
using QuestPDF.Drawing;
2021-12-19 05:11:23 +01:00
using QuestPDF.Examples.Engine;
using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;
using IContainer = QuestPDF.Infrastructure.IContainer;
2021-12-19 05:11:23 +01:00
namespace QuestPDF.Examples
{
public class TableExamples
{
public static Random Random { get; } = new Random();
[Test]
public void TemperatureReport()
{
RenderingTest
.Create()
.ProducePdf()
.PageSize(PageSizes.A4)
.MaxPages(10_000)
.EnableCaching()
.EnableDebugging(false)
.ShowResults()
2021-12-30 19:42:40 +01:00
.Render(container => GeneratePerformanceStructure(container, 250));
}
public static void GeneratePerformanceStructure(IContainer container, int repeats)
{
container
.Padding(25)
2021-12-30 19:42:40 +01:00
//.Background(Colors.Blue.Lighten2)
.Box()
2021-12-30 18:40:54 +01:00
.Border(1)
2021-12-30 19:42:40 +01:00
//.Background(Colors.Red.Lighten2)
.Table(table =>
{
table.ColumnsDefinition(columns =>
{
columns.ConstantColumn(100);
columns.RelativeColumn();
columns.ConstantColumn(100);
columns.RelativeColumn();
});
2021-12-27 18:24:37 +01:00
foreach (var i in Enumerable.Range(0, repeats))
{
table.Cell().RowSpan(3).LabelCell("Project");
2021-12-30 18:40:54 +01:00
table.Cell().RowSpan(3).ShowEntire().ValueCell(Placeholders.Sentence());
2021-12-27 18:24:37 +01:00
table.Cell().LabelCell("Report number");
table.Cell().ValueCell(i.ToString());
table.Cell().LabelCell("Date");
table.Cell().ValueCell(Placeholders.ShortDate());
table.Cell().LabelCell("Inspector");
table.Cell().ValueCell("Marcin Ziąbek");
table.Cell().ColumnSpan(2).LabelCell("Morning weather");
table.Cell().ColumnSpan(2).LabelCell("Evening weather");
table.Cell().ValueCell("Time");
table.Cell().ValueCell("7:13");
table.Cell().ValueCell("Time");
table.Cell().ValueCell("18:25");
table.Cell().ValueCell("Description");
table.Cell().ValueCell("Sunny");
table.Cell().ValueCell("Description");
table.Cell().ValueCell("Windy");
table.Cell().ValueCell("Wind");
table.Cell().ValueCell("Mild");
table.Cell().ValueCell("Wind");
table.Cell().ValueCell("Strong");
table.Cell().ValueCell("Temperature");
table.Cell().ValueCell("17°C");
table.Cell().ValueCell("Temperature");
table.Cell().ValueCell("32°C");
table.Cell().LabelCell("Remarks");
table.Cell().ColumnSpan(3).ValueCell(Placeholders.Paragraph());
}
});
}
2021-12-19 05:11:23 +01:00
}
}