I can't figure out how to create a new Google sheets in Swift 4 using the Sheets API. I would also like the use the same Google sheets later on in my code and so I would need it to return a value for the spreadsheet ID. This is what I have so far.
func createNewSheet() {
let url = NSURL(string: "https://sheets.googleapis.com/v4/spreadsheets")
let task = URLSession.shared.dataTask(with: url! as URL) {
(data, response, error) in
print(NSString(data: data!, encoding: String.Encoding.utf8.rawValue)!)
}
task.resume()
print (task)
}
var ss = SpreadsheetApp. getActiveSpreadsheet(); ss. insertSheet('My New Sheet'); Where 'My New Sheet' is the name you want it to be.
There's an Add a Sheet guide from the docs:
The following spreadsheets.batchUpdate request adds a sheet to a spreadsheet, while also setting the title, size, and tab color. This request returns an AddSheetResponse, consisting of an object with the created sheet's properties (such as its sheetId).
The request protocol is shown below. The Updating Spreadsheets guide shows how to implement a batch update in different languages using the Google API client libraries.
POST https://sheets.googleapis.com/v4/spreadsheets/spreadsheetId:batchUpdate
{
"requests": [
{
"addSheet": {
"properties": {
"title": "Deposits",
"gridProperties": {
"rowCount": 20,
"columnCount": 12
},
"tabColor": {
"red": 1.0,
"green": 0.3,
"blue": 0.4
}
}
}
}
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With