TableWithHeaderCellsSpanningMultipleColumnsTests.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 TableWithHeaderCellsSpanningMultipleColumnsTests : 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. columns.RelativeColumn();
  31. });
  32. table.Header(header =>
  33. {
  34. header.Cell().RowSpan(2).Element(HeaderCellStyle).Text("Paper Type");
  35. header.Cell().ColumnSpan(2).Element(HeaderCellStyle).Text("Width");
  36. header.Cell().ColumnSpan(2).Element(HeaderCellStyle).Text("Height");
  37. header.Cell().Element(HeaderCellStyle).Text("Inches");
  38. header.Cell().Element(HeaderCellStyle).Text("Points");
  39. header.Cell().Element(HeaderCellStyle).Text("Inches");
  40. header.Cell().Element(HeaderCellStyle).Text("Points");
  41. });
  42. table.Cell().AsSemanticHorizontalHeader().Element(HeaderCellStyle).Text("A3");
  43. table.Cell().Element(CellStyle).Text(Placeholders.Decimal());
  44. table.Cell().Element(CellStyle).Text(Placeholders.Decimal());
  45. table.Cell().Element(CellStyle).Text(Placeholders.Decimal());
  46. table.Cell().Element(CellStyle).Text(Placeholders.Decimal());
  47. table.Cell().AsSemanticHorizontalHeader().Element(HeaderCellStyle).Text("A4");
  48. table.Cell().Element(CellStyle).Text(Placeholders.Decimal());
  49. table.Cell().Element(CellStyle).Text(Placeholders.Decimal());
  50. table.Cell().Element(CellStyle).Text(Placeholders.Decimal());
  51. table.Cell().Element(CellStyle).Text(Placeholders.Decimal());
  52. table.Cell().AsSemanticHorizontalHeader().Element(HeaderCellStyle).Text("A5");
  53. table.Cell().Element(CellStyle).Text(Placeholders.Decimal());
  54. table.Cell().Element(CellStyle).Text(Placeholders.Decimal());
  55. table.Cell().Element(CellStyle).Text(Placeholders.Decimal());
  56. table.Cell().Element(CellStyle).Text(Placeholders.Decimal());
  57. IContainer HeaderCellStyle(IContainer container) =>
  58. container
  59. .Border(1)
  60. .BorderColor(Colors.Grey.Lighten2)
  61. .Background(Colors.Grey.Lighten3)
  62. .Padding(8)
  63. .AlignMiddle()
  64. .DefaultTextStyle(x => x.Bold());
  65. IContainer CellStyle(IContainer container) =>
  66. container
  67. .Border(1)
  68. .BorderColor(Colors.Grey.Lighten2)
  69. .Padding(8);
  70. });
  71. });
  72. });
  73. }
  74. protected override SemanticTreeNode? GetExpectedSemanticTree()
  75. {
  76. return ExpectedSemanticTree.DocumentRoot(root =>
  77. {
  78. root.Child("Table", table =>
  79. {
  80. table.Child("THead", thead =>
  81. {
  82. thead.Child("TR", row =>
  83. {
  84. row.Child("TH", th => th
  85. .Id(5)
  86. .Attribute("Table", "RowSpan", 2)
  87. .Child("P"));
  88. row.Child("TH", th => th
  89. .Id(6)
  90. .Attribute("Table", "ColSpan", 2)
  91. .Child("P"));
  92. row.Child("TH", th => th
  93. .Id(7)
  94. .Attribute("Table", "ColSpan", 2)
  95. .Child("P"));
  96. });
  97. thead.Child("TR", row =>
  98. {
  99. row.Child("TH", th => th
  100. .Id(9)
  101. .Attribute("Table", "Headers", new[] { 6 })
  102. .Child("P"));
  103. row.Child("TH", th => th
  104. .Id(10)
  105. .Attribute("Table", "Headers", new[] { 6 })
  106. .Child("P"));
  107. row.Child("TH", th => th
  108. .Id(11)
  109. .Attribute("Table", "Headers", new[] { 7 })
  110. .Child("P"));
  111. row.Child("TH", th => th
  112. .Id(12)
  113. .Attribute("Table", "Headers", new[] { 7 })
  114. .Child("P"));
  115. });
  116. });
  117. table.Child("TBody", tbody =>
  118. {
  119. tbody.Child("TR", row =>
  120. {
  121. row.Child("TH", th => th
  122. .Id(22)
  123. .Attribute("Table", "Headers", new[] { 5 })
  124. .Child("P"));
  125. row.Child("TD", th => th
  126. .Id(23)
  127. .Attribute("Table", "Headers", new[] { 6, 9, 22 })
  128. .Child("P"));
  129. row.Child("TD", td => td
  130. .Id(24)
  131. .Attribute("Table", "Headers", new[] { 6, 10, 22 })
  132. .Child("P"));
  133. row.Child("TD", td => td
  134. .Id(25)
  135. .Attribute("Table", "Headers", new[] { 7, 11, 22 })
  136. .Child("P"));
  137. row.Child("TD", td => td
  138. .Id(26)
  139. .Attribute("Table", "Headers", new[] { 7, 12, 22 })
  140. .Child("P"));
  141. });
  142. tbody.Child("TR", row =>
  143. {
  144. row.Child("TH", th => th
  145. .Id(28)
  146. .Attribute("Table", "Headers", new[] { 5 })
  147. .Child("P"));
  148. row.Child("TD", th => th
  149. .Id(29)
  150. .Attribute("Table", "Headers", new[] { 6, 9, 28 })
  151. .Child("P"));
  152. row.Child("TD", td => td
  153. .Id(30)
  154. .Attribute("Table", "Headers", new[] { 6, 10, 28 })
  155. .Child("P"));
  156. row.Child("TD", td => td
  157. .Id(31)
  158. .Attribute("Table", "Headers", new[] { 7, 11, 28 })
  159. .Child("P"));
  160. row.Child("TD", td => td
  161. .Id(32)
  162. .Attribute("Table", "Headers", new[] { 7, 12, 28 })
  163. .Child("P"));
  164. });
  165. tbody.Child("TR", row =>
  166. {
  167. row.Child("TH", th => th
  168. .Id(34)
  169. .Attribute("Table", "Headers", new[] { 5 })
  170. .Child("P"));
  171. row.Child("TD", th => th
  172. .Id(35)
  173. .Attribute("Table", "Headers", new[] { 6, 9, 34 })
  174. .Child("P"));
  175. row.Child("TD", td => td
  176. .Id(36)
  177. .Attribute("Table", "Headers", new[] { 6, 10, 34 })
  178. .Child("P"));
  179. row.Child("TD", td => td
  180. .Id(37)
  181. .Attribute("Table", "Headers", new[] { 7, 11, 34 })
  182. .Child("P"));
  183. row.Child("TD", td => td
  184. .Id(38)
  185. .Attribute("Table", "Headers", new[] { 7, 12, 34 })
  186. .Child("P"));
  187. });
  188. });
  189. });
  190. });
  191. }
  192. }