Modifying Headers - Adding Column Names to the Column Labels

From Q
Jump to: navigation, search

This rule adds the Column Names (by default A, B, C...) to the column headings in the table.

Example

AddingNamesRule.PNG

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.

OR

  • 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).

JavaScript

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

form.setSummary("Add Column Names to the Column Labels");
if (table.availableStatistics.indexOf('Column Names') == -1)
    form.ruleNotApplicable('Column Names are not available for this table.')
else {
    var column_names = table.get('Column Names')[0];  // Get the column names
    var column_labels = table.columnLabels;  // Get the standard column labels.
    var eol = '\r\n';   // '\r\n' is a special carriage-return code.
    for (var column = 0; column < table.numberColumns; column++)
       column_labels[column] = column_labels[column] + eol + column_names[column];
    table.columnLabels = column_labels;  // Set the adjusted column labels.
}
Personal tools
Namespaces

Variants
Actions
Navigation
Categories
Toolbox