TableExamples.cs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System;
  2. using System.ComponentModel;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using NUnit.Framework;
  6. using QuestPDF.Drawing;
  7. using QuestPDF.Examples.Engine;
  8. using QuestPDF.Fluent;
  9. using QuestPDF.Helpers;
  10. using QuestPDF.Infrastructure;
  11. using IContainer = QuestPDF.Infrastructure.IContainer;
  12. namespace QuestPDF.Examples
  13. {
  14. public class TableExamples
  15. {
  16. public static Random Random { get; } = new Random();
  17. [Test]
  18. public void TemperatureReport()
  19. {
  20. RenderingTest
  21. .Create()
  22. .ProduceImages()
  23. .PageSize(PageSizes.A4)
  24. .MaxPages(10_000)
  25. .EnableCaching()
  26. .EnableDebugging(false)
  27. .ShowResults()
  28. .Render(container => GeneratePerformanceStructure(container, 10));
  29. }
  30. public static void GeneratePerformanceStructure(IContainer container, int repeats)
  31. {
  32. container
  33. .Padding(25)
  34. //.Background(Colors.Blue.Lighten2)
  35. .Box()
  36. .Border(1)
  37. //.Background(Colors.Red.Lighten2)
  38. .Table(table =>
  39. {
  40. table.ColumnsDefinition(columns =>
  41. {
  42. columns.ConstantColumn(100);
  43. columns.RelativeColumn();
  44. columns.ConstantColumn(100);
  45. columns.RelativeColumn();
  46. });
  47. foreach (var i in Enumerable.Range(0, repeats))
  48. {
  49. table.Cell().RowSpan(3).LabelCell("Project");
  50. table.Cell().RowSpan(3).ShowEntire().ValueCell(Placeholders.Sentence());
  51. table.Cell().LabelCell("Report number");
  52. table.Cell().ValueCell(i.ToString());
  53. table.Cell().LabelCell("Date");
  54. table.Cell().ValueCell(Placeholders.ShortDate());
  55. table.Cell().LabelCell("Inspector");
  56. table.Cell().ValueCell("Marcin Ziąbek");
  57. table.Cell().ColumnSpan(2).LabelCell("Morning weather");
  58. table.Cell().ColumnSpan(2).LabelCell("Evening weather");
  59. table.Cell().ValueCell("Time");
  60. table.Cell().ValueCell("7:13");
  61. table.Cell().ValueCell("Time");
  62. table.Cell().ValueCell("18:25");
  63. table.Cell().ValueCell("Description");
  64. table.Cell().ValueCell("Sunny");
  65. table.Cell().ValueCell("Description");
  66. table.Cell().ValueCell("Windy");
  67. table.Cell().ValueCell("Wind");
  68. table.Cell().ValueCell("Mild");
  69. table.Cell().ValueCell("Wind");
  70. table.Cell().ValueCell("Strong");
  71. table.Cell().ValueCell("Temperature");
  72. table.Cell().ValueCell("17°C");
  73. table.Cell().ValueCell("Temperature");
  74. table.Cell().ValueCell("32°C");
  75. table.Cell().LabelCell("Remarks");
  76. table.Cell().ColumnSpan(3).ValueCell(Placeholders.Paragraph());
  77. }
  78. });
  79. }
  80. }
  81. }