TableWithHeaderCellsSpanningMultipleRowsTests.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. using QuestPDF.ConformanceTests.TestEngine;
  2. using QuestPDF.Drawing;
  3. using QuestPDF.Fluent;
  4. using QuestPDF.Helpers;
  5. using QuestPDF.Infrastructure;
  6. namespace QuestPDF.ConformanceTests.Table;
  7. internal class TableWithHeaderCellsSpanningMultipleRowsTests : ConformanceTestBase
  8. {
  9. protected override Document GetDocumentUnderTest()
  10. {
  11. return Document
  12. .Create(document =>
  13. {
  14. document.Page(page =>
  15. {
  16. page.Margin(60);
  17. page.Content()
  18. .Shrink()
  19. .Border(1)
  20. .BorderColor(Colors.Grey.Darken1)
  21. .SemanticTable()
  22. .Table(table =>
  23. {
  24. table.ColumnsDefinition(columns =>
  25. {
  26. columns.RelativeColumn();
  27. columns.RelativeColumn();
  28. columns.RelativeColumn();
  29. columns.RelativeColumn();
  30. });
  31. table.Header(header =>
  32. {
  33. header.Cell().Element(HeaderCellStyle).Text("Year");
  34. header.Cell().Element(HeaderCellStyle).Text("Quarter");
  35. header.Cell().Element(HeaderCellStyle).Text("Outcome");
  36. header.Cell().Element(HeaderCellStyle).Text("Income");
  37. });
  38. table.Cell().RowSpan(4).AsSemanticHorizontalHeader().Element(HeaderCellStyle).Text("2024");
  39. table.Cell().AsSemanticHorizontalHeader().Element(HeaderCellStyle).Text("Q1");
  40. table.Cell().Element(CellStyle).Text(Placeholders.Price());
  41. table.Cell().Element(CellStyle).Text(Placeholders.Price());
  42. table.Cell().AsSemanticHorizontalHeader().Element(HeaderCellStyle).Text("Q2");
  43. table.Cell().Element(CellStyle).Text(Placeholders.Price());
  44. table.Cell().Element(CellStyle).Text(Placeholders.Price());
  45. table.Cell().AsSemanticHorizontalHeader().Element(HeaderCellStyle).Text("Q3");
  46. table.Cell().Element(CellStyle).Text(Placeholders.Price());
  47. table.Cell().Element(CellStyle).Text(Placeholders.Price());
  48. table.Cell().AsSemanticHorizontalHeader().Element(HeaderCellStyle).Text("Q4");
  49. table.Cell().Element(CellStyle).Text(Placeholders.Price());
  50. table.Cell().Element(CellStyle).Text(Placeholders.Price());
  51. table.Cell().RowSpan(2).AsSemanticHorizontalHeader().Element(HeaderCellStyle).Text("2025");
  52. table.Cell().AsSemanticHorizontalHeader().Element(HeaderCellStyle).Text("Q1");
  53. table.Cell().Element(CellStyle).Text(Placeholders.Price());
  54. table.Cell().Element(CellStyle).Text(Placeholders.Price());
  55. table.Cell().AsSemanticHorizontalHeader().Element(HeaderCellStyle).Text("Q2");
  56. table.Cell().Element(CellStyle).Text(Placeholders.Price());
  57. table.Cell().Element(CellStyle).Text(Placeholders.Price());
  58. IContainer HeaderCellStyle(IContainer container) =>
  59. container
  60. .Border(1)
  61. .BorderColor(Colors.Grey.Lighten2)
  62. .Background(Colors.Grey.Lighten3)
  63. .Padding(8)
  64. .AlignMiddle()
  65. .DefaultTextStyle(x => x.Bold());
  66. IContainer CellStyle(IContainer container) =>
  67. container
  68. .Border(1)
  69. .BorderColor(Colors.Grey.Lighten2)
  70. .Padding(8);
  71. });
  72. });
  73. });
  74. }
  75. protected override SemanticTreeNode? GetExpectedSemanticTree()
  76. {
  77. return ExpectedSemanticTree.DocumentRoot(root =>
  78. {
  79. root.Child("Table", table =>
  80. {
  81. table.Child("THead", thead =>
  82. {
  83. thead.Child("TR", row =>
  84. {
  85. row.Child("TH", th => th.Id(5).Child("P"));
  86. row.Child("TH", th => th.Id(6).Child("P"));
  87. row.Child("TH", th => th.Id(7).Child("P"));
  88. row.Child("TH", th => th.Id(8).Child("P"));
  89. });
  90. });
  91. table.Child("TBody", tbody =>
  92. {
  93. tbody.Child("TR", row =>
  94. {
  95. row.Child("TH", th => th
  96. .Id(15)
  97. .Attribute("Table", "RowSpan", 4)
  98. .Attribute("Table", "Headers", new[] { 5 })
  99. .Child("P"));
  100. row.Child("TH", th => th
  101. .Id(16)
  102. .Attribute("Table", "Headers", new[] { 6, 15 })
  103. .Child("P"));
  104. row.Child("TD", td => td
  105. .Id(17)
  106. .Attribute("Table", "Headers", new[] { 7, 15, 16 })
  107. .Child("P"));
  108. row.Child("TD", td => td
  109. .Id(18)
  110. .Attribute("Table", "Headers", new[] { 8, 15, 16 })
  111. .Child("P"));
  112. });
  113. tbody.Child("TR", row =>
  114. {
  115. row.Child("TH", th => th
  116. .Id(20)
  117. .Attribute("Table", "Headers", new[] { 6, 15 })
  118. .Child("P"));
  119. row.Child("TD", td => td
  120. .Id(21)
  121. .Attribute("Table", "Headers", new[] { 7, 15, 20 })
  122. .Child("P"));
  123. row.Child("TD", td => td
  124. .Id(22)
  125. .Attribute("Table", "Headers", new[] { 8, 15, 20 })
  126. .Child("P"));
  127. });
  128. tbody.Child("TR", row =>
  129. {
  130. row.Child("TH", th => th
  131. .Id(24)
  132. .Attribute("Table", "Headers", new[] { 6, 15 })
  133. .Child("P"));
  134. row.Child("TD", td => td
  135. .Id(25)
  136. .Attribute("Table", "Headers", new[] { 7, 15, 24 })
  137. .Child("P"));
  138. row.Child("TD", td => td
  139. .Id(26)
  140. .Attribute("Table", "Headers", new[] { 8, 15, 24 })
  141. .Child("P"));
  142. });
  143. tbody.Child("TR", row =>
  144. {
  145. row.Child("TH", th => th
  146. .Id(28)
  147. .Attribute("Table", "Headers", new[] { 6, 15 })
  148. .Child("P"));
  149. row.Child("TD", td => td
  150. .Id(29)
  151. .Attribute("Table", "Headers", new[] { 7, 15, 28 })
  152. .Child("P"));
  153. row.Child("TD", td => td
  154. .Id(30)
  155. .Attribute("Table", "Headers", new[] { 8, 15, 28 })
  156. .Child("P"));
  157. });
  158. tbody.Child("TR", row =>
  159. {
  160. row.Child("TH", th => th
  161. .Id(32)
  162. .Attribute("Table", "RowSpan", 2)
  163. .Attribute("Table", "Headers", new[] { 5 })
  164. .Child("P"));
  165. row.Child("TH", th => th
  166. .Id(33)
  167. .Attribute("Table", "Headers", new[] { 6, 32 })
  168. .Child("P"));
  169. row.Child("TD", td => td
  170. .Id(34)
  171. .Attribute("Table", "Headers", new[] { 7, 32, 33 })
  172. .Child("P"));
  173. row.Child("TD", td => td
  174. .Id(35)
  175. .Attribute("Table", "Headers", new[] { 8, 32, 33 })
  176. .Child("P"));
  177. });
  178. tbody.Child("TR", row =>
  179. {
  180. row.Child("TH", th => th
  181. .Id(37)
  182. .Attribute("Table", "Headers", new[] { 6, 32 })
  183. .Child("P"));
  184. row.Child("TD", td => td
  185. .Id(38)
  186. .Attribute("Table", "Headers", new[] { 7, 32, 37 })
  187. .Child("P"));
  188. row.Child("TD", td => td
  189. .Id(39)
  190. .Attribute("Table", "Headers", new[] { 8, 32, 37 })
  191. .Child("P"));
  192. });
  193. });
  194. });
  195. });
  196. }
  197. }