Create a Spreadsheet

This page describes how to create a new spreadsheet.

Example

To create a new spreadsheet, use the create() method on the spreadsheet collection as shown in the following example. This example creates a blank spreadsheet with a specified title.

Apps Script

sheets/api/spreadsheet_snippets.gs
// This code uses the Sheets Advanced Service, but for most use cases
// the built-in method SpreadsheetApp.create() is more appropriate.
var sheet = Sheets.newSpreadsheet();
sheet.properties = Sheets.newSpreadsheetProperties();
sheet.properties.title = title;
var spreadsheet = Sheets.Spreadsheets.create(sheet);

Java

sheets/snippets/src/main/java/SpreadsheetSnippets.java
Spreadsheet spreadsheet = new Spreadsheet()
        .setProperties(new SpreadsheetProperties()
                .setTitle(title));
spreadsheet = service.spreadsheets().create(spreadsheet)
        .setFields("spreadsheetId")
        .execute();
System.out.println("Spreadsheet ID: " + spreadsheet.getSpreadsheetId());

JavaScript

sheets/snippets/snippets.js
gapi.client.sheets.spreadsheets.create({
  properties: {
    title: title
  }
}).then((response) => {
});

Node.js

sheets/snippets/snippets.js
const resource = {
  properties: {
    title,
  },
};
this.sheetsService.spreadsheets.create({
  resource,
  fields: 'spreadsheetId',
}, (err, spreadsheet) =>{
  if (err) {
    // Handle error.
    console.log(err);
  } else {
    console.log(`Spreadsheet ID: ${spreadsheet.spreadsheetId}`);
  }
});

PHP

sheets/snippets/src/SpreadsheetSnippets.php
<?php
$spreadsheet = new Google_Service_Sheets_Spreadsheet([
    'properties' => [
        'title' => $title
    ]
]);
$spreadsheet = $service->spreadsheets->create($spreadsheet, [
    'fields' => 'spreadsheetId'
]);
printf("Spreadsheet ID: %s\n", $spreadsheet->spreadsheetId);

Python

sheets/snippets/spreadsheet_snippets.py
spreadsheet = {
    'properties': {
        'title': title
    }
}
spreadsheet = service.spreadsheets().create(body=spreadsheet,
                                    fields='spreadsheetId').execute()
print('Spreadsheet ID: {0}'.format(spreadsheet.get('spreadsheetId')))

Ruby

sheets/snippets/lib/spreadsheet_snippets.rb
spreadsheet = {
  properties: {
    title: 'Sales Report'
  }
}
spreadsheet = service.create_spreadsheet(spreadsheet,
                                         fields: 'spreadsheetId')
puts "Spreadsheet ID: #{spreadsheet.spreadsheet_id}"