Modify Cell Content - Shade NET Rows and Columns

From Q
Jump to navigation Jump to search

This rule shades any NET rows or columns in a user-selected color.



How to apply this rule

For the first time in a project

  • Select the table(s)/chart(s) that you wish to apply the rule to.
  • Start typing the name of the Rule into the Search features and data box in the top right of the Q window.
  • Click on the Rule when it appears in the QScripts and Rules section of the search results.


  • Select Automate > Browse Online Library.
  • Choose this rule from the list.

Additional applications of the rule

  • Select a table or chart that has the rule and any table(s)/chart(s) that you wish to apply the rule to.
  • Click on the Rules tab (bottom-left of the table/chart).
  • Select the rule that you wish to apply.
  • Click on the Apply drop-down and choose your desired option.
  • Check New items to have it automatically applied to new items that you create. Use Edit > Project Options > Save as Template to create a new project template that automatically uses this rule.

Removing the rule

  • Select the table(s)/chart(s) that you wish to remove the rule from.
  • Press the Rules tab (bottom-right corner).
  • Press Apply next to the rule you wish to remove and choose the appropriate option.

How to modify the rule

  • Click on the Rules tab (bottom-left of the table/chart).
  • Select the rule that you wish to modify.
  • Click Edit Rule and make the desired changes. Alternatively, you can use the JavaScript below to make your own rule (see Customizing Rules).


You can find a simpler version of this code, which does not contain the controls, here.

includeWeb('Table JavaScript Utility Functions'); 


// Set up controls for user input.
form.setHeading('Shade NET Rows and Columns');
form.setSummary('Shade NET rows and columns');
let description = form.newLabel('Add color to cells in the NET (or SUM) rows and columns');
description.lineBreakAfter = true;
let color_label = form.newLabel('Color for NET/SUM:');
let color_picker = form.newColorPicker('color');

form.setInputControls([description, color_label, color_picker]);


// Fetch the array of cell colors (one entry for each cell).
let colors = table.cellColors;
let shade = color_picker.getValue();

let net_name = getNetName();

// Find NET rows
let net_rows = table.netRows;
table.rowLabels.forEach(function (row_label, index) {
    if (row_label == net_name && net_rows.indexOf(index) == -1)

// Shade NET rows
net_rows.forEach(function (row) {
    for (let column = 0; column < table.numberColumns; column++)
        colors[row][column] = shade;

if (table.columnLabels != null) {
    // Find NET columns
    let net_columns = table.netColumns;
    table.columnLabels.forEach(function (column_label, index) {
        if (column_label == net_name && net_columns.indexOf(index) == -1)

    // Shade NET rows
    net_columns.forEach(function (column) {
        for (let row = 0; row < table.numberRows; row++)
            colors[row][column] = shade;

// Apply colors to the cells
table.cellColors = colors;

function getNetName() {
    let net_name = 'NET';
    if (table.getTranslation)
        net_name = table.getTranslation(net_name);
    return net_name;

See also