-1

I have been looking all over the docs ( for hours ) can't find what I'm supposed to do to retrieve a (public - owned by me) spreadsheet document to parse and display on the page .

edit 1

I figured out how to make the request but getting a 403 err

{
    "error": {
        "code": 403, 
        "message": "The request is missing a valid API key.", 
        "status": "PERMISSION_DENIED"
    }
}

how to attach my api key to the request ??

1 Answers1

0

Here's a simple example that I did for someone else but then they withdrew their question. It will read the contents of a spreadsheet and display it on a dialog as a table and it also reads all of the sheets in your spreadsheet and displays that on a sidebar.

function anExample()
{
  var ss=SpreadsheetApp.getActive();
  var sht=ss.getActiveSheet();
  var rng=sht.getDataRange();
  var rngA=rng.getValues();
  var html='';
  html+='<table>';
  for(var i=0;i<rngA.length;i++)
  {
    if(i>0){s+='<br />';}
    for(var j=0;j<rngA[0].length;j++)
    {
      html+='<td>' + rngA[i][j] + '<td>' //This how you can access of the values in the spread sheet rngA[i][j]
    }
    html+='</tr>'
  }
  html+='</table>';
  var output=HtmlService.createHtmlOutput(html).setWidth(800).setHeight(450);
  SpreadsheetApp.getUi().showModelessDialog(output, "My Data");
  var allsheets=ss.getSheets();//This is how you could iterate through all of the sheets in your spreadsheet
  var s='';
  for(var i=0;i<allsheets.length;i++)
  {
    if(i>0){s+=', ';}
    s+=allsheets[i].getName();
  }
  var userInterface=HtmlService.createHtmlOutput(s);
  SpreadsheetApp.getUi().showSidebar(userInterface);//This will display all of the sheets in your spreadsheet
}
Cooper
  • 59,616
  • 6
  • 23
  • 54
  • could you mention what libraries should I include ? I see that you have few global variables like `SpreadsheetApp` and `HtmlService` –  Aug 01 '17 at 10:34
  • My best advice is to create a Spreadsheet and go to the tools menu and select "script editor" and in the "script editor" go to the help menu and pick any one of the selections. They all take you to the Google Apps Script API. I spend most of my time in Guides and Reference. Everything you need to know is pretty well documented in there. If you need additional help Google it and very often you will be lead back here to stackoverflow.com where there are other volunteer programmers ready to assist you. [API reference](https://developers.google.com/apps-script/reference/calendar/). – Cooper Aug 01 '17 at 12:48