1

I use the code below and get the following error:

Exception: You are not allowed to use SpreadsheetApp.create. Required permissions: https://www.googleapis.com/auth/spreadsheets (Zeile 4, Datei "Makros"). (this works now!)

function Auswertung2() {
  var sheet = SpreadsheetApp.getActive().getSheetByName("Evaluation");
  var newSpreadsheet = SpreadsheetApp.create("new spreadsheet");
  var newSheet = newSpreadsheet.getSheets()[0];
  var chart = sheet.getCharts()[0];
  chart = chart.modify().addRange(sheet.getRange("A1:AX80")).setPosition(7, 7, 0, 0).build();
  newSheet.insertChart(chart); 
};
greenster10
  • 79
  • 1
  • 9

1 Answers1

0

SpreadsheetApp is going to run from whoever's gmail is logged in when they cause the script to run. It is up to them to click the authorize pop up box. Even if they did this it wouldn't be created in YOUR Google Drive but THEIR Google Drive. If you want these sheets to be installed in your Google Drive you need to "install" the function under your account.

https://developers.google.com/apps-script/guides/triggers/installable

In the script editor to the left of the run button and to the right of the save button is a little clock icon, you click that to install triggers in the middle bottom of the screen you will see "create a new trigger" this will make it so no matter what gmail they are using it will access your gmail google drive. Warning though it will give them unlimited access to YOUR SpreadsheetApp... so for example anyone with write permission to your spreadsheet could literally now delete all of your spreadsheets that is why they make authorization such a process.

CodeCamper
  • 6,609
  • 6
  • 44
  • 94
  • and do you have a solution how I can avoid this error now? maybe edit the code? – greenster10 Nov 15 '19 at 07:41
  • what have triggers to domwith that problem? I don't understand what you mean with the triggers? – greenster10 Nov 15 '19 at 08:03
  • @greenster10 click the link provided to read about installable triggers, if you run your code from an installable trigger as I have instructed you to do then the code will always run from your gmail, if you run it any other way it will run from the person's gmail who is in the spreadsheet which may or may not be your intention. Are you trying to create a spreadsheet in someone else's google drive or ONLY your google drive? – CodeCamper Nov 17 '19 at 05:49
  • I try to create a spreadheet for anyone who runs the link, so in someone else's google drive – greenster10 Nov 18 '19 at 06:45
  • 1
    @greenster10 each user needs to manually give your app permission, you can't just get permission for everyone in the world, you could change your code at any time to delete all the files in their google drive for example. – CodeCamper Nov 18 '19 at 06:52
  • it works now, can you show me how to implement the addRange function to my Code? – greenster10 Nov 18 '19 at 07:04
  • 1
    @greenster10 do you want to modify your original question, what do you mean addRange function? What are you trying to accomplish? – CodeCamper Nov 18 '19 at 07:35
  • I edited the original question, can you help me with the problem? My function only inserts an empty sheet... but I want to insert the data from sheet Evaluation, where a chart already exists into a new spreadsheet. – greenster10 Nov 18 '19 at 07:45
  • @greenster10 you should change your question back to the way it was and mark this as the answer, you should ask a new question because you are literally asking so many different questions. You should give a very specific example with sample data, desired output, and current output. – CodeCamper Nov 18 '19 at 07:52
  • https://stackoverflow.com/questions/58910199/why-does-the-addrange-function-not-work-in-google-apps-script here is the new question, could you please help me, I accepted your answer here! – greenster10 Nov 18 '19 at 08:04