Specify Names for Tables in the Report
Q names the tables and charts in the report with the contents of the blue and brown drop-down menus for each table. Sometimes you may need to override these names with your own names, or those specified by a client. While names can be entered manually by right-clicking an item in the report and selecting Rename, you can also rename the items in your report using a QScript. The script below allows you to enter the list of names that you want to use, and it then goes through the items in the report, from top to bottom, and replaces their names with those in the list. If you make changes to the tables and need to rename them again, the script can be re-run.
To change the names, simply change the list at the top called table_names. The order of the list must match the order of tables in your project.
includeWeb("QScript Table Functions");
// Specify your list of table names here
var table_names = ["Table 1",
"Table 2",
"Table 3"];
// Renaming items in the "Report"
var target_group = project.report;
// Get all of the tables, plots, and other items in the report.
var items = [];
recursiveGetAllItemsInGroup(target_group, items);
// Rename tables/plots/etc in order of their appearance in the report.
if (table_names.length > items.length)
log("There are more names specified in this script (" + table_names.length + ") than there are items in the report (" + items.length +"). Modify the list of names and run the script again.");
else {
table_names.forEach(function (name, ind) {
items[ind].name = name;
});
}
if (items.length > table_names.length)
log("There are more items in the report (" + items.length + ") than there are names specified in this script (" + table_names.length +"). Some items have not been renamed.");
See also
- QScript for an explanation of how to run this code.
- QScript Examples Library for other examples.
- QScript Reference for technical information.
- JavaScript for information about the JavaScript programming language.
- Table JavaScript and Plot JavaScript for tools for using JavaScript to modify the appearance of tables and charts.
- JavaScript Variables for detail on how to create new variables in the Variables and Questions tab using JavaScript.