问题
I'm looking for a way to read the contents of the script.gs files within a standalone Google Apps Script. I can't find a suitable getAs() Mime format in the Docslist.File service that doesn't fail. The context of this is that I want to use the html service/content service to be able to embed public GAS source samples in Google Sites and elsewhere. (in much the same way as embedding Gist Samples). Any ideas?
回答1:
It is, in fact, possible. This gets Code.gs:
function myFunction() {
throw ScriptApp.getResource("Code").getDataAsString();
}
回答2:
There is no way to programmatically retrieve the contents of a ".gs" file. You can only ask for files with ".html" extension and potentially you can return it in a project.
This request has come up in the context of allow local development or Git integration to provide an API way to get/set script source in a file. Please put your comments in this issue tracker request or log a new one if it makes sense .
http://code.google.com/p/google-apps-script-issues/issues/detail?id=1108
来源:https://stackoverflow.com/questions/13210469/is-it-possible-to-read-the-contents-of-a-google-apps-script-from-another-script