human art and other bits

Google Spreadsheets + Zend Framework and PHP

, posted: 21-Jul-2009 13:12

Well,  I've been teaching myself PHP and my students so lazy, I don't know why I bother.

I used Xampp, Zend framework on windows.  To setup the zend framework in with Xampp I had to change,

The php.ini to enable ssl
- and to add the include path of the library
       include_path = ".;C:\xampp\htdocs\wtf_google\library"

I made a Spreadsheet in Google Docs,  called GdataTestSheet, It had a number of worksheets.

Here's the code, don't be evil with it.

/* Load the Zend Gdata classes. */

require_once 'Zend/Loader.php';

$user="google user name";
$pass="your google password";

$service = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
$spreadsheetService = new Zend_Gdata_Spreadsheets($client);
$feed = $spreadsheetService->getSpreadsheetFeed();

$i = 0;
foreach($feed->entries as $entry) {                // All you spreadsheet files
            $tetitle = $entry->title->text;        // grab the title of the spread sheet

            if ($tetitle == "GdataTestSheet"){     // is it the spreadsheet GdataTestSheet?
                echo "Spreadsheet name: ".$tetitle."\n";
                $teid = $entry->id;               // grab the ID for the GdataTestSheet Spreadsheet
                echo $teid." id: ";

    $spreadsheetsKey = basename($teid);       // returns the $id needed when using documents
    echo "".$spreadsheetsKey."\n";

    $query = new Zend_Gdata_Spreadsheets_DocumentQuery();
    $feed = $spreadsheetService->getWorksheetFeed($query);

    echo "We have found the work sheets, find the worksheetId\n";

    foreach($feed->entries as $entry) {       // bad use of loop but I was not writing a loop must fix
        echo $entry->title->text;
        echo "ID ";                           // set one you want  - im using the last one
        $worksheetId = basename($entry->id);  // get the worksheet id
        echo $worksheetId."\n";

    $query = new Zend_Gdata_Spreadsheets_CellQuery();
    $query->setSpreadsheetKey($spreadsheetsKey);             // spreadsheet id
    $query->setWorksheetId($worksheetId);                    // worksheet id
    $cellFeed = $spreadsheetService->getCellFeed($query);

    //  displays cells
    foreach($cellFeed as $cellEntery){
        echo $row.",".$col."=".$val."\n";

    // writes to cell 2, colom 2,  dog
    $updateCell=$spreadsheetService->updateCell(2, 2, "dog", $spreadsheetsKey, $worksheetId)

       // comments welcome

Other related posts:
EASEUS Todo Backup – my favourite backup software
Jolicloud on the netbook
A couple of new things on my EeePC 1001HA

hellonearthisman's profile

Brett Cooper
New Zealand

Stone artist with a digital understanding. 1st computer was a c=64