问题
I have to work with google spreadsheets. I am using some template spreadsheets which all contain a lot of links to other spreadsheets. The problem is that whenever I make a copy of the template spreadsheet to use most of the links(created with the importrange function) require me to give them access again
What I want to do is make a script that would allow me to import all the links in one press. I tried to make an app script but I can't found any way to access the textbox with the "allow access" button so that i can make my script. My questions are: is there any way to access the "allow access" button programatically? or is there any other way to solve my problem and allow access to all links in one press?
回答1:
I had to face to the same issue. The only way to avoid this Allow Access for importrange is to put the linked document (destination of the importrange) public, or shared by the link, which is public too, but if readers have the link. Then there is no requirement of authorizing importrange. Google should avoid this authorization access if the 2 documents are from the same owner, I don't understand where is the security breach here.
回答2:
Well, what I've done doesn't really solve the problem, but helps a lot. I imported the range of all Spreadsheets I wanted to a third Spreadsheet. Then I imported that range to my model. So, when a new file is created, you only have to allow access to one Spreadsheet instead of many.
As I said, it doesn't solve the problem but it is a nice workaround.
回答3:
No, you can't access "Allow Access" button programatically, because it would be a security breach in a system.
I think that the best way to grant access will be iterating through list of spreadsheets' ids and opening them like this:
var idList = [...]; // here are all the ids
for (var i = 0; i < idList.length; i++) {
SpreadsheetApp.openById(idList[i]); // trying to open the spreadsheet by id
}
That way user should be asked to grant access to script to access every spreadsheet automatically.
Then you should be able to import ranges from script rather than from the spreadsheet itself. Use Spreadsheet and Sheet classes and getRange() method in particular.
来源:https://stackoverflow.com/questions/25178205/how-can-i-make-an-apps-script-to-instantly-allow-access-to-all-imported-elements