Google Spreadsheets + Zend Framework and PHP
Random kind of messed up geek thoughts, 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
extension=php_openssl.dll
- 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.
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
extension=php_openssl.dll
- 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';
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="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: ";
}
$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, "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
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="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: ";
}
$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, "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
Tag(s): 
Please note: comments that are inappropriate or promotional in nature will be deleted. E-mail addresses are not displayed, but you must enter a valid e-mail address to confirm your comments.
Are you a registered Geekzone user? Login to have the fields below automatically filled in for you and to enable links in comments. If you have (or qualify to have) a Geekzone Blog then your comment will be automatically confirmed and placed in the moderation queue for the blog owner's approval.