GData Reference Manual: GDataDocumentsSpreadsheet

## GDataDocumentsSpreadsheet GDataDocumentsSpreadsheet — GData Documents spreadsheet object |

## Stability Level

Unstable, unless otherwise indicated

## Synopsis

    #include <gdata/services/documents/gdata-documents-spreadsheet.h>

    #define             GDATA_DOCUMENTS_SPREADSHEET_CSV
    #define             GDATA_DOCUMENTS_SPREADSHEET_HTML
    #define             GDATA_DOCUMENTS_SPREADSHEET_ODS
    #define             GDATA_DOCUMENTS_SPREADSHEET_PDF
    #define             GDATA_DOCUMENTS_SPREADSHEET_TSV
    #define             GDATA_DOCUMENTS_SPREADSHEET_XLS
                        GDataDocumentsSpreadsheet;
                        GDataDocumentsSpreadsheetClass;
    GDataDocumentsSpreadsheet * gdata_documents_spreadsheet_new
                                                            (const gchar *id);
    gchar *             gdata_documents_spreadsheet_get_download_uri
                                                            (GDataDocumentsSpreadsheet *self,
                                                             const gchar *export_format,
                                                             gint gid);

## Object Hierarchy

      GObject
       +----GDataParsable
             +----GDataEntry
                   +----GDataDocumentsEntry
                         +----GDataDocumentsDocument
                               +----GDataDocumentsSpreadsheet

## Implemented Interfaces

GDataDocumentsSpreadsheet implements GDataAccessHandler.

## Description

GDataDocumentsSpreadsheet is a subclass of GDataDocumentsDocument to represent a spreadsheet from Google Documents.

For more details of Google Documents' GData API, see the online documentation.

Example 37. Downloading a Specific Sheet of a Spreadsheet

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    GDataDocumentsService *service;
    GDataDocumentsSpreadsheet *spreadsheet;
    GFile *destination_file;
    guint gid;
    gchar *download_uri;
    GDataDownloadStream *download_stream;
    GFileOutputStream *output_stream;
    GError *error = NULL;

    /* Create a service and retrieve the spreadsheet and sheet index (GID) to download and the file to save the download in */
    service = create_youtube_service ();
    spreadsheet = get_document_to_download (service);
    destination_file = query_user_for_destination_file (spreadsheet);
    gid = query_user_for_gid (spreadsheet);

    /* Create the download stream */
    download_uri = gdata_documents_spreadsheet_get_download_uri (spreadsheet, GDATA_DOCUMENTS_SPREADSHEET_CSV, gid);
    download_stream = GDATA_DOWNLOAD_STREAM (gdata_download_stream_new (service, gdata_documents_service_get_spreadsheet_authorization_domain (),
                                                                        download_uri, NULL));
    g_free (download_uri);

    g_object_unref (spreadsheet);
    g_object_unref (service);

    /* Create the file output stream */
    output_stream = g_file_replace (destination_file, NULL, FALSE, G_FILE_CREATE_REPLACE_DESTINATION, NULL, &error);

    g_object_unref (destination_file);

    if (error != NULL) {
        g_error ("Error creating destination file: %s", error->message);
        g_error_free (error);
        g_object_unref (download_stream);
        return;
    }

    /* Download the document. This should almost always be done asynchronously. */
    g_output_stream_splice (G_OUTPUT_STREAM (output_stream), G_INPUT_STREAM (download_stream),
                            G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, NULL, &error);

    g_object_unref (output_stream);
    g_object_unref (download_stream);

    if (error != NULL) {
        g_error ("Error downloading spreadsheet: %s", error->message);
        g_error_free (error);
        return;
    }

## Details

### GDATA_DOCUMENTS_SPREADSHEET_CSV

    #define GDATA_DOCUMENTS_SPREADSHEET_CSV "csv"

The export format for Comma-Separated Values (CSV) format.

For more information, see the GData protocol specification.

Since 0.7.0

### GDATA_DOCUMENTS_SPREADSHEET_HTML

    #define GDATA_DOCUMENTS_SPREADSHEET_HTML "html"

The export format for HyperText Markup Language (HTML) format.

For more information, see the GData protocol specification.

Since 0.7.0

### GDATA_DOCUMENTS_SPREADSHEET_ODS

    #define GDATA_DOCUMENTS_SPREADSHEET_ODS "ods"

The export format for OpenDocument Spreadsheet (ODS) format.

For more information, see the GData protocol specification.

Since 0.7.0

### GDATA_DOCUMENTS_SPREADSHEET_PDF

    #define GDATA_DOCUMENTS_SPREADSHEET_PDF "pdf"

The export format for Portable Document Format (PDF).

For more information, see the GData protocol specification.

Since 0.7.0

### GDATA_DOCUMENTS_SPREADSHEET_TSV

    #define GDATA_DOCUMENTS_SPREADSHEET_TSV "tsv"

The export format for Tab-Separated Values (TSV) format.

For more information, see the GData protocol specification.

Since 0.7.0

### GDATA_DOCUMENTS_SPREADSHEET_XLS

    #define GDATA_DOCUMENTS_SPREADSHEET_XLS "xls"

The export format for Microsoft Excel spreadsheet (XLS) format.

For more information, see the GData protocol specification.

Since 0.7.0

### GDataDocumentsSpreadsheet

    typedef struct _GDataDocumentsSpreadsheet GDataDocumentsSpreadsheet;

All the fields in the GDataDocumentsSpreadsheet structure are private and should never be accessed directly.

Since 0.4.0

### GDataDocumentsSpreadsheetClass

    typedef struct {
    } GDataDocumentsSpreadsheetClass;

All the fields in the GDataDocumentsSpreadsheetClass structure are private and should never be accessed directly.

Since 0.4.0

### gdata_documents_spreadsheet_new ()

    GDataDocumentsSpreadsheet * gdata_documents_spreadsheet_new
                                                            (const gchar *id);

Creates a new GDataDocumentsSpreadsheet with the given entry ID ("id").

`id` : | the entry's ID (not the document ID of the spreadsheet), or `NULL`. [allow-none]
Returns : | a new GDataDocumentsSpreadsheet, or `NULL`; unref with `g_object_unref()`. [transfer full]

Since 0.4.0

### gdata_documents_spreadsheet_get_download_uri ()

    gchar *             gdata_documents_spreadsheet_get_download_uri
                                                            (GDataDocumentsSpreadsheet *self,
                                                             const gchar *export_format,
                                                             gint gid);

Builds and returns the download URI for the given GDataDocumentsSpreadsheet in the desired format. Note that directly downloading the document using this URI isn't possible, as authentication is required. You should instead use `gdata_download_stream_new()` with the URI, and use the resulting GInputStream.

When requesting a `"csv"`, `"tsv"`, `"pdf"` or `"html"` file you may specify an additional parameter called `gid` which indicates which grid, or sheet, you wish to get (the index is `0`-based, so GID `1` actually refers to the second sheet on a given spreadsheet).

`self` : | a GDataDocumentsSpreadsheet
`export_format` : | the format in which the spreadsheet should be exported when downloaded
`gid` : | the `0`-based sheet ID to download, or `-1`
Returns : | the download URI; free with `g_free()`

Since 0.5.0