Introduction
This article describes how to go from a standard table...
...to a table with spans or sub-headings:
Requirements
- A table. In this example, we are adding row spans, so the labels you want to create spans for must exist in the rows.
- You have read How to Create a Custom Rule.
Method
1. Select your table.
2. Go to Automate > Custom Rule in the toolbar.
3. Paste the below into the dialog:
form.setHeading("Add row spans");
form.setSummary("Add row spans");
// Span the Coke brands.
table.spanRows([table.rowIndex('Coca-Cola'),
table.rowIndex('Diet Coke'),
table.rowIndex('Coke Zero')],
'Coke Brands');
// Span the Pepsi brands.
table.spanRows([table.rowIndex('Diet Pepsi'),
table.rowIndex('Pepsi Max'),
table.rowIndex('Pepsi')],
'Pepsi Brands');
- In this code, we use
table.spanRows
to define the rows to be covered by the span. The format for the arguments istable.spanRows([index1,index2,...], label)
, whereby we usetable.rowIndex
to return the index of the specified label. - Note, unlike when creating a span via a table's context menu, this change is only made to tables with this Rule applied.
4. OPTIONAL: If you have a crosstab and then switch rows and columns, you will need to apply this rule to the columns instead. In this case, you should update the function references to spanColumns
and columnIndex
respectively.
5. Press the blue Play button > Close > OK.
Next
How to Add a Custom Table Footnote
See Also
How to Make One Column Appear After Another in a Table
How to Automatically Rename Row Labels in Tables
How to Hide Empty Rows and Columns in a Table
How to Add an Average of Each Row to a Table