Do you expect the Javascript file you wish to "inject" to change regularly? If not, the easiest way will be to make a new script file in your project, and add the content of the file you want to inject. For instance, let's say you start with Code.gs
with just one function, based heavily on the Spreadsheets project template:
/**
* Adds a custom menu to the active spreadsheet
*/
function onOpen() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var entries = [{
name : "Tell a Joke",
functionName : "beFunny"
}];
spreadsheet.addMenu("Script Center Menu", entries);
};
You see I'm calling "beFunny()" which is not in this file. Instead, it's in a new file, ExtraStuff.gs
:
function beFunny() {
Browser.msgBox('Waka waka waka');
}
Run this, and the Tell a Joke
menu item works, even though nothing in Code.gs
refers to the existence of another script file. Instead, the functions and variables declared in of all of the files in the project are "in scope" for one another.