Using Google SpreadsheetsThe Google Spreadsheets data API allows client applications to view and update Spreadsheets content in the form of Google data API feeds. Your client application can request a list of a user's spreadsheets, edit or delete content in an existing Spreadsheets worksheet, and query the content in an existing Spreadsheets worksheet. See » http://code.google.com/apis/spreadsheets/overview.html for more information about the Google Spreadsheets API. Create a SpreadsheetThe Spreadsheets data API does not currently provide a way to programmatically create or delete a spreadsheet. Get a List of Spreadsheets
You can get a list of spreadsheets for a particular user by using
the
Get a List of WorksheetsA given spreadsheet may contain multiple worksheets. For each spreadsheet, there's a worksheets metafeed listing all the worksheets in that spreadsheet. Given the spreadsheet key from the <id> of a Zend_Gdata_Spreadsheets_SpreadsheetEntry object you've already retrieved, you can fetch a feed containing a list of worksheets associated with that spreadsheet.
The resulting Zend_Gdata_Spreadsheets_WorksheetFeed
object feed represents the response from the server. Among other
things, this feed contains a list of
Zend_Gdata_Spreadsheets_WorksheetEntry
objects ( Interacting With List-based FeedsA given worksheet generally contains multiple rows, each containing multiple cells. You can request data from the worksheet either as a list-based feed, in which each entry represents a row, or as a cell-based feed, in which each entry represents a single cell. For information on cell-based feeds, see Interacting with cell-based feeds. The following sections describe how to get a list-based feed, add a row to a worksheet, and send queries with various query parameters. The list feed makes some assumptions about how the data is laid out in the spreadsheet. In particular, the list feed treats the first row of the worksheet as a header row; Spreadsheets dynamically creates XML elements named after the contents of header-row cells. Users who want to provide Gdata feeds should not put any data other than column headers in the first row of a worksheet. The list feed contains all rows after the first row up to the first blank row. The first blank row terminates the data set. If expected data isn't appearing in a feed, check the worksheet manually to see whether there's an unexpected blank row in the middle of the data. In particular, if the second row of the spreadsheet is blank, then the list feed will contain no data. A row in a list feed is as many columns wide as the worksheet itself. Get a List-based Feed
To retrieve a worksheet's list feed, use the
The resulting Zend_Gdata_Spreadsheets_ListFeed
object $listfeed represents a response from the
server. Among other things, this feed contains an array of
Zend_Gdata_Spreadsheets_ListEntry objects
(
Each Zend_Gdata_Spreadsheets_ListEntry contains an
array,
An alternate version of this array,
Reverse-sort RowsBy default, rows in the feed appear in the same order as the corresponding rows in the GUI; that is, they're in order by row number. To get rows in reverse order, set the reverse properties of the Zend_Gdata_Spreadsheets_ListQuery object to TRUE:
Note that if you want to order (or reverse sort) by a
particular column, rather than by position in the worksheet,
you can set the Send a Structured Query
You can set a Zend_Gdata_Spreadsheets_ListQuery's
Add a Row
Rows can be added to a spreadsheet by using the
The $rowData parameter contains an array of column keys to data values. The method returns a Zend_Gdata_Spreadsheets_SpreadsheetsEntry object which represents the inserted row. Spreadsheets inserts the new row immediately after the last row that appears in the list-based feed, which is to say immediately before the first entirely blank row. Edit a Row
Once a Zend_Gdata_Spreadsheets_ListEntry object
is fetched, its rows can be updated by using the
The $oldListEntry parameter contains the list entry to be updated. $newRowData contains an array of column keys to data values, to be used as the new row data. The method returns a Zend_Gdata_Spreadsheets_SpreadsheetsEntry object which represents the updated row. Delete a Row
To delete a row, simply invoke
Alternatively, you can call the
Interacting With Cell-based FeedsIn a cell-based feed, each entry represents a single cell. Note that we don't recommend interacting with both a cell-based feed and a list-based feed for the same worksheet at the same time. Get a Cell-based Feed
To retrieve a worksheet's cell feed, use the
The resulting Zend_Gdata_Spreadsheets_CellFeed
object $cellFeed represents a response from the
server. Among other things, this feed contains an array of
Zend_Gdata_Spreadsheets_CellEntry objects
(
Send a Cell Range QuerySuppose you wanted to retrieve the cells in the first column of a worksheet. You can request a cell feed containing only this column as follows:
This requests all the data in column 1, starting with row 2. Change Contents of a Cell
To modify the contents of a cell, call
The new data is placed in the specified cell in the worksheet.
If the specified cell contains data already, it will be
overwritten. Note: Use
|
|