Version v4 of the Google Sheets API is now available! This migration guide shows how to update applications to use v4.

Manage Worksheets

A given spreadsheet may contain multiple worksheets. Each spreadsheet has a worksheets feed listing all of its worksheets.

The following sections describe how to create a spreadsheet, get a set of worksheets, add a worksheet to a spreadsheet, update the metadata of a worksheet, and remove a worksheet from the spreadsheet.

Create a spreadsheet

It is possible to create a new spreadsheet by uploading a spreadsheet file via the Google Drive API. The Sheets API does not currently provide a way to delete a spreadsheet, but this is also provided in the Google Drive API. For testing purposes, you may create a spreadsheet manually or upload one.

Sheets API URLs, visibilities, and projections

The Sheets API supports visibilities and projections in request URLs. Visibilities determine whether or not authorization should be used for a request. Projections determine which data is returned in a response to a request. Visibilities and projections are set in request URLs to the API.

An example Sheets API URL reads:

https://spreadsheets.google.com/feeds/worksheets/key/private/full

URLs similar to that one are returned by the Sheets API in various link elements in feed responses. When working with the API, applications can change the keywords private and full, in order to manipulate API functionality slightly. URLs returned by the API after having changed these keywords will reflect the keywords used in the source request.

That is, if the following request is made to the API:

GET https://spreadsheets.google.com/feeds/worksheets/key/private/basic

Then the cells feed URLs in each worksheet entry are of the form:

https://spreadsheets.google.com/feeds/cells/key/worksheetId/private/basic

And the list feed URLs in each worksheet entry are of the form:

https://spreadsheets.google.com/feeds/list/key/worksheetId/private/basic

Note that the basic projection is already set on these generated URLs. The same applies for the public visibility described below.

There are other visibility and projection values available besides private and full.

The private visibility can be replaced with the public visibility, which enables the feed to work without authorization for spreadsheets that have been "Published to the Web". The public visibility is supported on the worksheets, list, and cells feeds. The public visibility is useful for accessing the contents of a spreadsheet from the client context of a web page in JavaScript, for example.

To publish a spreadsheet to the web, select File > Publish to the web from the Google Sheets user interface, then click Publish.

The full projection can be replaced with the basic projection, causing the feed to return less information (i.e. fewer fields, and only the most important data). This is better for low-bandwidth environments. The basic projection is supported on the worksheets, list, and cells feeds.

Retrieve a list of spreadsheets

The Google Sheets API supports fetching a list of spreadsheets for the authenticated user. Note however that you cannot create or delete spreadsheets via this API. For those operations, you must use the Google Drive API.

This API operation is accessible only with authorized requests. Requests that have not been authorized cannot access this feed (i.e. this feed is not public).

HTTP

You can request a feed containing a list of the currently authenticated user's spreadsheets by sending an authenticated GET request to the following URL:

https://spreadsheets.google.com/feeds/spreadsheets/private/full

The result is a feed that lists all of user's spreadsheets.

An entry in the spreadsheets feed might resemble the following. The following example has been edited a little to make it a little more readable by humans; in particular, a real spreadsheets feed contains actual spreadsheet IDs where the following listing says key.

<entry gd:etag=""FDHGCHnx12"">
  <id>https://spreadsheets.google.com/feeds/spreadsheets/tNXTXMh83yMWLVJfEgOWTvQ</id>
  <updated>2011-05-27T15:08:37.102Z</updated>
  <category scheme="http://schemas.google.com/spreadsheets/2006" term="http://schemas.google.com/spreadsheets/2006#spreadsheet"/>
  <title>My Spreadsheet</title>
  <content type="application/atom+xml;type=feed" src="https://spreadsheets.google.com/feeds/worksheets/tNXTXMh83yMWLVJfEgOWTvQ/private/full"/>
  <link rel="http://schemas.google.com/spreadsheets/2006#tablesfeed" type="application/atom+xml" href="https://spreadsheets.google.com/feeds/tNXTXMh83yMWLVJfEgOWTvQ/tables"/>
  <link rel="alternate" type="text/html" href="https://spreadsheets.google.com/ccc?key=0Ak8c_1IVge120199weAHSjDHf1XTFZKZkVnT1dUdlE"/>
  <link rel="self" type="application/atom+xml" href="https://spreadsheets.google.com/feeds/spreadsheets/private/full/tNXTXMh83yMWLVJfEgOWTvQ"/>
  <author>
    <name>joe</name>
    <email>joe@yourdomain.com</email>
  </author>
</entry>

Note that the key value that appears here is the same as the key value that appears in the URL displayed in the address bar of your browser window when you open the spreadsheet manually.

The URI given in the link element with rel="http://schemas.google.com/spreadsheets/2006#tablesfeed" is the URI of the worksheets feed for that spreadsheet, which lists all the worksheets the user has access to in that spreadsheet. If that URI ends with /private/values, that indicates that the current authenticated user can only view the spreadsheet, not edit it. If it ends with /private/full, that indicates that the current authenticated user is authorized to add and edit data in the worksheets.

Java

The following code fetches a list of all spreadsheets owned or shared with an authorized user, and prints out the title of each spreadsheet.

import com.google.gdata.client.spreadsheet.*;
import com.google.gdata.data.spreadsheet.*;
import com.google.gdata.util.*;

import java.io.IOException;
import java.net.*;
import java.util.*;

public class MySpreadsheetIntegration {
  public static void main(String[] args)
      throws AuthenticationException, MalformedURLException, IOException, ServiceException {

    SpreadsheetService service =
        new SpreadsheetService("MySpreadsheetIntegration-v1");

    // TODO: Authorize the service object for a specific user (see other sections)

    // Define the URL to request.  This should never change.
    URL SPREADSHEET_FEED_URL = new URL(
        "https://spreadsheets.google.com/feeds/spreadsheets/private/full");

    // Make a request to the API and get all spreadsheets.
    SpreadsheetFeed feed = service.getFeed(SPREADSHEET_FEED_URL, SpreadsheetFeed.class);
    List<SpreadsheetEntry> spreadsheets = feed.getEntries();

    // Iterate through all of the spreadsheets returned
    for (SpreadsheetEntry spreadsheet : spreadsheets) {
      // Print the title of this spreadsheet to the screen
      System.out.println(spreadsheet.getTitle().getPlainText());
    }
  }
}

.NET

The following code fetches a list of all spreadsheets owned or shared with an authorized user, and prints out the title of each spreadsheet.

using System;
using Google.GData.Client;
using Google.GData.Spreadsheets;

namespace MySpreadsheetIntegration
{
  class Program
  {
    static void Main(string[] args)
    {
      SpreadsheetsService service = new SpreadsheetsService("MySpreadsheetIntegration-v1");

      // TODO: Authorize the service object for a specific user (see other sections)

      // Instantiate a SpreadsheetQuery object to retrieve spreadsheets.
      SpreadsheetQuery query = new SpreadsheetQuery();

      // Make a request to the API and get all spreadsheets.
      SpreadsheetFeed feed = service.Query(query);

      // Iterate through all of the spreadsheets returned
      foreach (SpreadsheetEntry entry in feed.Entries)
      {
        // Print the title of this spreadsheet to the screen
        Console.WriteLine(entry.Title.Text);
      }
    }
  }
}

If no entries are returned, it means there are no spreadsheets created or shared by this account. Creating a spreadsheet and requesting the feed again yields a spreadsheet entry.

Retrieve information about worksheets

A set of metadata can be fetched about each worksheet, as well as information that enables further manipulation of data in the worksheet.

HTTP

To determine the URL of a given spreadsheet's worksheets feed, find that spreadsheet's entry in the spreadsheets feed, as described in the previous section. Then examine the link element that has rel="http://schemas.google.com/spreadsheets/2006#tablesfeed". That element's href value provides the URL for that spreadsheet's worksheets feed.

To request a list of worksheets in a given spreadsheet, issue a GET request to that URL, with an appropriate authorization header:

GET https://spreadsheets.google.com/feeds/worksheets/key/private/full

The API returns a feed resembling the following. The word key in the following example is used only to make the sample more readable.

<feed xmlns="http://www.w3.org/2005/Atom"
    xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/"
    xmlns:gs="http://schemas.google.com/spreadsheets/2006"
    xmlns:gd="http://schemas.google.com/g/2005"
    gd:etag='W/"D0cERnk-eip7ImA9WBBXGEg."'>
  <id>https://spreadsheets.google.com/feeds/worksheets/key/private/full</id>
  <updated>2006-11-17T18:23:45.173Z</updated>
  <title type="text">Groceries R Us</title>
  <link rel="alternate" type="text/html"
      href="https://spreadsheets.google.com/ccc?key=key"/>
  <link rel="http://schemas.google.com/g/2005#feed"
      type="application/atom+xml"
      href="https://spreadsheets.google.com/feeds/worksheets/key/private/full"/>
  <link rel="self" type="application/atom+xml"
      href="https://spreadsheets.google.com/feeds/worksheets/key/private/full"/>
  <link rel="http://schemas.google.com/g/2005#post" type="application/atom+xml"
      href="https://spreadsheets.google.com/feeds/worksheets/key/private/full"/>
  <author>
    <name>Fitzwilliam Darcy</name>
    <email>fitz@gmail.com</email>
  </author>
  <openSearch:totalResults>1</openSearch:totalResults>
  <openSearch:startIndex>1</openSearch:startIndex>
  <openSearch:itemsPerPage>1</openSearch:itemsPerPage>
  <entry gd:etag='"YDwqeyI."'>
    <id>https://spreadsheets.google.com/feeds/worksheets/key/private/full/worksheetId</id>
    <updated>2006-11-17T18:23:45.173Z</updated>
    <title type="text">Sheet1</title>
    <content type="text">Sheet1</content>
    <link rel="http://schemas.google.com/spreadsheets/2006#listfeed"
        type="application/atom+xml"
        href="https://spreadsheets.google.com/feeds/list/key/worksheetId/private/full"/>
    <link rel="http://schemas.google.com/spreadsheets/2006#cellsfeed"
        type="application/atom+xml"
        href="https://spreadsheets.google.com/feeds/cells/key/worksheetId/private/full"/>
    <link rel="self" type="application/atom+xml"
        href="https://spreadsheets.google.com/feeds/worksheets/key/private/full/worksheetId"/>
    <link rel="edit" type="application/atom+xml"
        href="https://spreadsheets.google.com/feeds/worksheets/key/private/full/worksheetId/version"/>
    <gs:rowCount>100</gs:rowCount>
    <gs:colCount>20</gs:colCount>
  </entry>
</feed>

Java

The following code fetches a list of worksheets for the first spreadsheet in a feed. It first prints out the title of the spreadsheet, and then prints a list of all worksheets in that spreadsheet. Each item in the list shows the title, number of rows, and number of columns of the worksheet.

import com.google.gdata.client.spreadsheet.*;
import com.google.gdata.data.spreadsheet.*;
import com.google.gdata.util.*;

import java.io.IOException;
import java.net.*;
import java.util.*;

public class MySpreadsheetIntegration {
  public static void main(String[] args)
      throws AuthenticationException, MalformedURLException, IOException, ServiceException {

    SpreadsheetService service =
        new SpreadsheetService("MySpreadsheetIntegration-v1");

    // TODO: Authorize the service object for a specific user (see other sections)

    // Define the URL to request.  This should never change.
    URL SPREADSHEET_FEED_URL = new URL(
        "https://spreadsheets.google.com/feeds/spreadsheets/private/full");

    // Make a request to the API and get all spreadsheets.
    SpreadsheetFeed feed = service.getFeed(SPREADSHEET_FEED_URL,
        SpreadsheetFeed.class);
    List<SpreadsheetEntry> spreadsheets = feed.getEntries();

    if (spreadsheets.size() == 0) {
      // TODO: There were no spreadsheets, act accordingly.
    }

    // TODO: Choose a spreadsheet more intelligently based on your
    // app's needs.
    SpreadsheetEntry spreadsheet = spreadsheets.get(0);
    System.out.println(spreadsheet.getTitle().getPlainText());

    // Make a request to the API to fetch information about all
    // worksheets in the spreadsheet.
    List<WorksheetEntry> worksheets = spreadsheet.getWorksheets();

    // Iterate through each worksheet in the spreadsheet.
    for (WorksheetEntry worksheet : worksheets) {
      // Get the worksheet's title, row count, and column count.
      String title = worksheet.getTitle().getPlainText();
      int rowCount = worksheet.getRowCount();
      int colCount = worksheet.getColCount();

      // Print the fetched information to the screen for this worksheet.
      System.out.println("\t" + title + "- rows:" + rowCount + " cols: " + colCount);
    }
  }
}

.NET

The following code fetches a list of worksheets for the first spreadsheet in a feed. It first prints out the title of the spreadsheet, and then prints a list of all worksheets in that spreadsheet. Each worksheet in the list shows the title, number of rows, and number of columns of the worksheet.

using System;
using Google.GData.Client;
using Google.GData.Spreadsheets;

namespace MySpreadsheetIntegration
{
  class Program
  {
    static void Main(string[] args)
    {
      SpreadsheetsService service = new SpreadsheetsService("MySpreadsheetIntegration-v1");

      // TODO: Authorize the service object for a specific user (see other sections)

      // Instantiate a SpreadsheetQuery object to retrieve spreadsheets.
      SpreadsheetQuery query = new SpreadsheetQuery();

      // Make a request to the API and get all spreadsheets.
      SpreadsheetFeed feed = service.Query(query);

      if (feed.Entries.Count == 0)
      {
        // TODO: There were no spreadsheets, act accordingly.
      }

      // TODO: Choose a spreadsheet more intelligently based on your
      // app's needs.
      SpreadsheetEntry spreadsheet = (SpreadsheetEntry)feed.Entries[0];
      Console.WriteLine(spreadsheet.Title.Text);

      // Make a request to the API to fetch information about all
      // worksheets in the spreadsheet.
      WorksheetFeed wsFeed = spreadsheet.Worksheets;

      // Iterate through each worksheet in the spreadsheet.
      foreach (WorksheetEntry entry in wsFeed.Entries)
      {
        // Get the worksheet's title, row count, and column count.
        string title = entry.Title.Text;
        int rowCount = entry.Rows;
        int colCount = entry.Cols;

        // Print the fetched information to the screen for this worksheet.
        Console.WriteLine(title + "- rows:" + rowCount + " cols: " + colCount);
      }
    }
  }
}

Add a worksheet

Worksheets can be created using the Sheets API. To do this, an application must make a request to the API containing information about the new worksheet, like its title and initial size.

HTTP

To add a worksheet to the spreadsheet, authenticate and authorize, then simply make the following HTTP request to a spreadsheet's worksheet feed URL. You must be authenticated and authorized to add worksheets via the Sheets API.

POST https://spreadsheets.google.com/feeds/worksheets/key/private/full
Content-Type: application/atom+xml

<entry xmlns="http://www.w3.org/2005/Atom"
    xmlns:gs="http://schemas.google.com/spreadsheets/2006">
  <title>Expenses</title>
  <gs:rowCount>50</gs:rowCount>
  <gs:colCount>10</gs:colCount>
</entry>

Java

The following code adds a new worksheet to the first spreadsheet returned from the API. The title of the created worksheet is New Worksheet. The new worksheet has 10 columns and 20 rows.

import com.google.gdata.client.spreadsheet.*;
import com.google.gdata.data.spreadsheet.*;
import com.google.gdata.util.*;

import java.io.IOException;
import java.net.*;
import java.util.*;

public class MySpreadsheetIntegration {
  public static void main(String[] args)
      throws AuthenticationException, MalformedURLException, IOException, ServiceException {

    SpreadsheetService service =
        new SpreadsheetService("MySpreadsheetIntegration-v1");

    // TODO: Authorize the service object for a specific user (see other sections)

    // Define the URL to request.  This should never change.
    URL SPREADSHEET_FEED_URL = new URL(
        "https://spreadsheets.google.com/feeds/spreadsheets/private/full");

    // Make a request to the API and get all spreadsheets.
    SpreadsheetFeed feed = service.getFeed(SPREADSHEET_FEED_URL,
        SpreadsheetFeed.class);
    List<SpreadsheetEntry> spreadsheets = feed.getEntries();

    if (spreadsheets.size() == 0) {
      // TODO: There were no spreadsheets, act accordingly.
    }

    // TODO: Choose a spreadsheet more intelligently based on your
    // app's needs.
    SpreadsheetEntry spreadsheet = spreadsheets.get(0);
    System.out.println(spreadsheet.getTitle().getPlainText());

    // Create a local representation of the new worksheet.
    WorksheetEntry worksheet = new WorksheetEntry();
    worksheet.setTitle(new PlainTextConstruct("New Worksheet"));
    worksheet.setColCount(10);
    worksheet.setRowCount(20);

    // Send the local representation of the worksheet to the API for
    // creation.  The URL to use here is the worksheet feed URL of our
    // spreadsheet.
    URL worksheetFeedUrl = spreadsheet.getWorksheetFeedUrl();
    service.insert(worksheetFeedUrl, worksheet);

  }
}

.NET

The following code adds a new worksheet to the first spreadsheet returned from the API. The title of the created worksheet is New Worksheet. The new worksheet has 10 columns and 20 rows.

using System;
using Google.GData.Client;
using Google.GData.Spreadsheets;

namespace MySpreadsheetIntegration
{
  class Program
  {
    static void Main(string[] args)
    {
      SpreadsheetsService service = new SpreadsheetsService("MySpreadsheetIntegration-v1");

      // TODO: Authorize the service object for a specific user (see other sections)

      // Instantiate a SpreadsheetQuery object to retrieve spreadsheets.
      SpreadsheetQuery query = new SpreadsheetQuery();

      // Make a request to the API and get all spreadsheets.
      SpreadsheetFeed feed = service.Query(query);

      if (feed.Entries.Count == 0)
      {
        // TODO: There were no spreadsheets, act accordingly.
      }

      // TODO: Choose a spreadsheet more intelligently based on your
      // app's needs.
      SpreadsheetEntry spreadsheet = (SpreadsheetEntry)feed.Entries[0];
      Console.WriteLine(spreadsheet.Title.Text);

      // Create a local representation of the new worksheet.
      WorksheetEntry worksheet = new WorksheetEntry();
      worksheet.Title.Text = "New Worksheet";
      worksheet.Cols = 10;
      worksheet.Rows = 20;

      // Send the local representation of the worksheet to the API for
      // creation.  The URL to use here is the worksheet feed URL of our
      // spreadsheet.
      WorksheetFeed wsFeed = spreadsheet.Worksheets;
      service.Insert(wsFeed, worksheet);
    }
  }
}

The new worksheet will appear after the last worksheet in the Sheets UI.

Modify a worksheet's title and size

You can modify the title and size of a worksheet with the Sheets API by sending a request to the API containing the new properties of the worksheet. If you need to modify the actual content of cells, see Adding a list row, or Changing contents of a cell.

HTTP

To change the title or size of a worksheet, begin by getting the desired worksheet from the worksheet feed. Then update the worksheet's metadata and send a PUT request with the desired entry contents to the URL provided in an edit link. The edit URL is highlighted in the XML below.

<entry>
  <id>
    https://spreadsheets.google.com/feeds/worksheets/key/private/full/worksheetId
  </id>
  <updated>2007-07-30T18:51:30.666Z</updated>
  <category scheme="http://schemas.google.com/spreadsheets/2006"
    term="http://schemas.google.com/spreadsheets/2006#worksheet"/>
  <title type="text">Income</title>
  <content type="text">Expenses</content>
  <link rel="http://schemas.google.com/spreadsheets/2006#listfeed"
    type="application/atom+xml" href="https://spreadsheets.google.com/feeds/list/key/worksheetId/private/full"/>
  <link rel="http://schemas.google.com/spreadsheets/2006#cellsfeed"
    type="application/atom+xml" href="https://spreadsheets.google.com/feeds/cells/key/worksheetId/private/full"/>
  <link rel="self" type="application/atom+xml"
    href="https://spreadsheets.google.com/feeds/worksheets/key/private/full/worksheetId"/>
  <link rel="edit" type="application/atom+xml"
    href="https://spreadsheets.google.com/feeds/worksheets/key/private/full/worksheetId/version"/>
  <gs:rowCount>45</gs:rowCount>
  <gs:colCount>15</gs:colCount>
</entry>

Java

The following code changes the title and dimensions of the first worksheet returned for the first spreadsheet in the spreadsheets feed. The title of the worksheet is changed to Updated Worksheet, the number of columns is set to 5, and the number of rows is set to 15.

import com.google.gdata.client.spreadsheet.*;
import com.google.gdata.data.spreadsheet.*;
import com.google.gdata.util.*;

import java.io.IOException;
import java.net.*;
import java.util.*;

public class MySpreadsheetIntegration {
  public static void main(String[] args)
      throws AuthenticationException, MalformedURLException, IOException, ServiceException {

    SpreadsheetService service =
        new SpreadsheetService("MySpreadsheetIntegration-v1");

    // TODO: Authorize the service object for a specific user (see other sections)

    // Define the URL to request.  This should never change.
    URL SPREADSHEET_FEED_URL = new URL(
        "https://spreadsheets.google.com/feeds/spreadsheets/private/full");

    // Make a request to the API and get all spreadsheets.
    SpreadsheetFeed feed = service.getFeed(SPREADSHEET_FEED_URL,
        SpreadsheetFeed.class);
    List<SpreadsheetEntry> spreadsheets = feed.getEntries();

    if (spreadsheets.size() == 0) {
      // TODO: There were no spreadsheets, act accordingly.
    }

    // TODO: Choose a spreadsheet more intelligently based on your
    // app's needs.
    SpreadsheetEntry spreadsheet = spreadsheets.get(0);
    System.out.println(spreadsheet.getTitle().getPlainText());

    // Get the first worksheet of the first spreadsheet.
    // TODO: Choose a worksheet more intelligently based on your
    // app's needs.
    WorksheetFeed worksheetFeed = service.getFeed(
        spreadsheet.getWorksheetFeedUrl(), WorksheetFeed.class);
    List<WorksheetEntry> worksheets = worksheetFeed.getEntries();
    WorksheetEntry worksheet = worksheets.get(0);

    // Update the local representation of the worksheet.
    worksheet.setTitle(new PlainTextConstruct("Updated Worksheet"));
    worksheet.setColCount(5);
    worksheet.setRowCount(15);

    // Send the local representation of the worksheet to the API for
    // modification.
    worksheet.update();
  }
}

.NET

The following code changes the title and dimensions of the first worksheet returned for the first spreadsheet in the spreadsheets feed. The title of the worksheet is changed to Updated Worksheet, the number of columns is set to 5, and the number of rows is set to 15.

using System;
using Google.GData.Client;
using Google.GData.Spreadsheets;

namespace MySpreadsheetIntegration
{
  class Program
  {
    static void Main(string[] args)
    {
      SpreadsheetsService service = new SpreadsheetsService("MySpreadsheetIntegration-v1");

      // TODO: Authorize the service object for a specific user (see other sections)

      // Instantiate a SpreadsheetQuery object to retrieve spreadsheets.
      SpreadsheetQuery query = new SpreadsheetQuery();

      // Make a request to the API and get all spreadsheets.
      SpreadsheetFeed feed = service.Query(query);

      if (feed.Entries.Count == 0)
      {
        // TODO: There were no spreadsheets, act accordingly.
      }

      // TODO: Choose a spreadsheet more intelligently based on your
      // app's needs.
      SpreadsheetEntry spreadsheet = (SpreadsheetEntry)feed.Entries[0];
      Console.WriteLine(spreadsheet.Title.Text);

      // Get the first worksheet of the first spreadsheet.
      // TODO: Choose a worksheet more intelligently based on your
      // app's needs.
      WorksheetFeed wsFeed = spreadsheet.Worksheets;
      WorksheetEntry worksheet = (WorksheetEntry)wsFeed.Entries[0];

      // Update the local representation of the worksheet.
      worksheet.Title.Text = "Updated Worksheet";
      worksheet.Cols = 5;
      worksheet.Rows = 15;

      // Send the local representation of the worksheet to the API for
      // modification.
      worksheet.Update();
    }
  }
}

Delete a worksheet

Worksheets can be deleted from a spreadsheet using the Sheets API.

When a worksheet is deleted, all worksheets to the right of it in the Sheets UI will be shifted left one position. The ID of the other worksheets will not change, however.

HTTP

To delete a worksheet, perform a DELETE request on the edit URL of a worksheet entry after obtaining it as described above.

DELETE https://spreadsheets.google.com/feeds/worksheets/key/private/full/worksheetId/version

Java

The following code deletes the first worksheet returned for the first spreadsheet in the spreadsheets feed.

import com.google.gdata.client.spreadsheet.*;
import com.google.gdata.data.spreadsheet.*;
import com.google.gdata.util.*;

import java.io.IOException;
import java.net.*;
import java.util.*;

public class MySpreadsheetIntegration {
  public static void main(String[] args)
      throws AuthenticationException, MalformedURLException, IOException, ServiceException {

    SpreadsheetService service =
        new SpreadsheetService("MySpreadsheetIntegration-v1");

    // TODO: Authorize the service object for a specific user (see other sections)

    // Define the URL to request.  This should never change.
    URL SPREADSHEET_FEED_URL = new URL(
        "https://spreadsheets.google.com/feeds/spreadsheets/private/full");

    // Make a request to the API and get all spreadsheets.
    SpreadsheetFeed feed = service.getFeed(SPREADSHEET_FEED_URL,
        SpreadsheetFeed.class);
    List<SpreadsheetEntry> spreadsheets = feed.getEntries();

    if (spreadsheets.size() == 0) {
      // TODO: There were no spreadsheets, act accordingly.
    }

    // TODO: Choose a spreadsheet more intelligently based on your
    // app's needs.
    SpreadsheetEntry spreadsheet = spreadsheets.get(0);
    System.out.println(spreadsheet.getTitle().getPlainText());

    // Get the first worksheet of the first spreadsheet.
    // TODO: Choose a worksheet more intelligently based on your
    // app's needs.
    WorksheetFeed worksheetFeed = service.getFeed(
        spreadsheet.getWorksheetFeedUrl(), WorksheetFeed.class);
    List<WorksheetEntry> worksheets = worksheetFeed.getEntries();
    WorksheetEntry worksheet = worksheets.get(0);

    // Delete the worksheet via the API.
    worksheet.delete();
  }
}

.NET

The following code deletes the first worksheet returned for the first spreadsheet in the spreadsheets feed.

using System;
using Google.GData.Client;
using Google.GData.Spreadsheets;

namespace MySpreadsheetIntegration
{
  class Program
  {
    static void Main(string[] args)
    {
      SpreadsheetsService service = new SpreadsheetsService("MySpreadsheetIntegration-v1");

      // TODO: Authorize the service object for a specific user (see other sections)

      // Instantiate a SpreadsheetQuery object to retrieve spreadsheets.
      SpreadsheetQuery query = new SpreadsheetQuery();

      // Make a request to the API and get all spreadsheets.
      SpreadsheetFeed feed = service.Query(query);

      if (feed.Entries.Count == 0)
      {
        // TODO: There were no spreadsheets, act accordingly.
      }

      // TODO: Choose a spreadsheet more intelligently based on your
      // app's needs.
      SpreadsheetEntry spreadsheet = (SpreadsheetEntry)feed.Entries[0];
      Console.WriteLine(spreadsheet.Title.Text);

      // Get the first worksheet of the first spreadsheet.
      // TODO: Choose a worksheet more intelligently based on your
      // app's needs.
      WorksheetFeed wsFeed = spreadsheet.Worksheets;
      WorksheetEntry worksheet = (WorksheetEntry)wsFeed.Entries[0];

      // Delete the worksheet via the API.
      worksheet.Delete();
    }
  }
}

Send feedback about...

Sheets API v3
Sheets API v3