@@ -143,3 +143,94 @@ Here is a full list of things you can customize:
143
143
$table->setStyle('colorful');
144
144
145
145
This method can also be used to override a built-in style.
146
+
147
+ Spanning multiple columns and rows
148
+ ----------------------------------
149
+
150
+ .. versionadded :: 2.7
151
+ Spanning multiple columns and rows was introduced in Symfony 2.7.
152
+
153
+ To make a table cell which spans multiple columns you can use a :class: `Symfony\\ Component\\ Console\\ Helper\\ TableCell `::
154
+
155
+ use Symfony\Component\Console\Helper\Table;
156
+ use Symfony\Component\Console\Helper\TableSeparator;
157
+ use Symfony\Component\Console\Helper\TableCell;
158
+
159
+ $table = new Table($output);
160
+ $table
161
+ ->setHeaders(array('ISBN', 'Title', 'Author'))
162
+ ->setRows(array(
163
+ array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri'),
164
+ new TableSeparator(),
165
+ array(new TableCell('This value spans 3 columns.', array('colspan' => 3))),
166
+ ))
167
+ ;
168
+ $table->render();
169
+
170
+ which results in:
171
+
172
+ .. code-block :: text
173
+
174
+ +---------------+---------------+-----------------+
175
+ | ISBN | Title | Author |
176
+ +---------------+---------------+-----------------+
177
+ | 99921-58-10-7 | Divine Comedy | Dante Alighieri |
178
+ +---------------+---------------+-----------------+
179
+ | This value spans 3 columns. |
180
+ +---------------+---------------+-----------------+
181
+
182
+ .. tip ::
183
+
184
+ You can create a multiple-line page title using a header cell that spans
185
+ the enire table width::
186
+
187
+ $table->setHeaders(array(
188
+ array(new TableCell('Main table title', array('colspan' => 3))),
189
+ array('ISBN', 'Title', 'Author'),
190
+ ))
191
+ // ...
192
+
193
+ This generates:
194
+
195
+ .. code-block :: text
196
+
197
+ +-------+-------+--------+
198
+ | Main table title |
199
+ +-------+-------+--------+
200
+ | ISBN | Title | Author |
201
+ +-------+-------+--------+
202
+ | ... |
203
+ +-------+-------+--------+
204
+
205
+ In a similar way you can span multiple rows::
206
+
207
+ use Symfony\Component\Console\Helper\Table;
208
+ use Symfony\Component\Console\Helper\TableCell;
209
+
210
+ $table = new Table($output);
211
+ $table
212
+ ->setHeaders(array('ISBN', 'Title', 'Author'))
213
+ ->setRows(array(
214
+ array(
215
+ '978-0521567817',
216
+ 'De Monarchia',
217
+ new TableCell("Dante Alighieri\nspans multiple rows", array('rowspan' => 2)),
218
+ ),
219
+ array('978-0804169127', 'Divine Comedy'),
220
+ ))
221
+ ;
222
+ $table->render();
223
+
224
+ which results in:
225
+
226
+ .. code-block :: text
227
+
228
+ +----------------+---------------+---------------------+
229
+ | ISBN | Title | Author |
230
+ +----------------+---------------+---------------------+
231
+ | 978-0521567817 | De Monarchia | Dante Alighieri |
232
+ | 978-0804169127 | Divine Comedy | spans multiple rows |
233
+ +----------------+---------------+---------------------+
234
+
235
+ You can use the ``colspan `` and ``rowspan `` options at the same time which allows
236
+ you to create any table layout you may wish.
0 commit comments