0
votes

I'm trying to create a Google Spreadsheet with two sheets or 'tabs' Using javascript. I can Create a sheet and add a title to a tab, but I can only create one tab. I have tried to use the addSheet property as well and it simply over-writes existing sheet. This is the data I'm trying to send as an example:

var data = {
  properties: {
    title: 'Data Sheet'
  },

  sheets: [{
    properties: {
      title: 'data A',
    },
    properties: {
      title: 'data B',
    }

  }]
};
1
This is not really a Google Apps Script question. Apps Script is a language based on Javascript that is used to create addons within Google Drive. I have proposed changes to your tags. - Chris
Thanks. First post... - Jacob Ruleaux
@Jacob Ruleaux Before I answer, I would like to confirm about your situation, because I would like to correctly understand it. 1. You can use Sheets API. 2. You want to create new Spreadsheet including 2 sheets. 3. Your issue is the request body and you want the correct request body for it. Is my understanding correct? - Tanaike
@Tanaike That is correct. I can create a spreadsheet using the API via javascript but can only seem to create a spreadsheet with one sheet. I would like two. The request body does not seem to work in the above format. I have tried different variations. - Jacob Ruleaux
I use this: $.ajax({ url: 'sheets.googleapis.com/v4/spreadsheets/…' + googleAPICreds.access_token, type: "POST", data: JSON.stringify(data), dataType: 'json', contentType: "application/json; charset=utf-8", success: function (response) { googleAPIHandler.saveSpreadsheetId(response); } }); console.log(googleAPICreds.access_token); - Jacob Ruleaux

1 Answers

0
votes

I was missing additional brackets around my data. Simple mistake:

var data = { properties: { title: 'Data Sheet' },

                    sheets : [
                        {
                            properties: {
                                title: 'data A',
                            }
                        },
                        {
                            properties: {
                                title: 'data B',
                            }
                        }
                    ]
                };