How can I make an apps script to instantly allow access to all imported elements in a Google Spreadsheet?

不羁的心 提交于 2019-11-26 22:26:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!