Working With Google Spreadsheets

So one of the projects I am working on at the moment needs to have creation/editing integration with Google Docs so that word processing and spreadsheet documents can be uploaded and created via the web app.

Unfortunately Google Spreadsheets doesn’t expose an API endpoint for creating a new blank spreadsheet, only for uploading an existing one. This is of course a problem.

The simple, if not elegant, solution for this is to create a blank spreadsheet document, add it to your web app and then upload it when creating a new, blank Spreadsheet document at Google.

Using the zend library for this, it would look like so:

private function upload($html, $originalFileName, $temporaryFileLocation) {
	self::bootstrap_zend();
	$docs = self::connect();
	$fileToUpload = $originalFileName;
		
	if( $temporaryFileLocation ) {
		$fileToUpload = $temporaryFileLocation;
  	}
  		
	return $docs->uploadFile( $fileToUpload, $originalFileName, null, Zend_Gdata_Docs::DOCUMENTS_LIST_FEED_URI );
}

Then simply call this code where and when you wish to create a new spreadsheet:

public static function create_spreadsheet($doc) {
	self::upload( $html, $doc->title, '/files/uploads/google/tmp.xls' );
}

In this example $doc is an object that is created by our custom app, since we want to save some data about this new spreadsheet on our end, and apply custom permissions to it, from within our custom app.

I hope this helps someone else who is tasked with this kind of problem.

252
days old
6
sentences
250
words
0
comments

Chris J. Davis

Monday September 12th, 2011

and

The Latest
No Comments.
The Latest