View Google Spreadsheet using PHP and Zend Gdata api
a PHP example
<?php
require_once ‘Zend/Loader.php’;
Zend_Loader::loadClass(‘Zend_Gdata_AuthSub’);
Zend_Loader::loadClass(‘Zend_Gdata_Gbase’);
Zend_Loader::loadClass(‘Zend_Gdata_Spreadsheets’);
Zend_Loader::loadClass(‘Zend_Gdata_ClientLogin’);$user=”xxx”;
$pass=”xxx”;
$spreadsheet =’Clones’;$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 sheetif ($tetitle == $spreadsheet){ // is it the spreadsheet GdataTestSheet?
echo “Spreadsheet name: “.$tetitle.”\n”;
$teid = $entry->id; // grab the ID for the GdataTestSheet Spreadsheet
echo $teid.” id: “;
}
$i++;
}$spreadsheetsKey = basename($teid); // returns the $id needed when using documents
echo “”.$spreadsheetsKey.”\n”;$query = new Zend_Gdata_Spreadsheets_DocumentQuery();
$query->setSpreadsheetKey($spreadsheetsKey);
$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){
$row=$cellEntery->cell->getRow();
$col=$cellEntery->cell->getColumn();
$val=$cellEntery->cell->getText();
echo $row.”,”.$col.”=”.$val.”\n”;
}// writes to cell 2, colom 2, dog
//$updateCell=$spreadsheetService->updateCell(2, 2, “cat & dog”, $spreadsheetsKey, $worksheetId)?>