[Warning! Buzzword-enabled text ahead!] GData APIs implement an Atom extension that enables remote document querying and editing. What’s more, query results can be obtained as evaluated JSON objects; this technique allows to bypass most cross-site scripting security constraints, so Ajax widgets can be implemented without control over the server side.
A tiny little script will get us the sheet’s contents. We only have to look for these pieces of information in order to make it work:
- Publishing key.
- Unique identifier for the desired sheet (a spreadsheet is organized as a book, so it can contain several sheets).
- Desired cell range.
These can be obtained from the feed publishing URL that appears in Publish/More publishing options in the Google Spreadsheets interface. There goes the script:
What the code does, in short, is dynamically inserting a
<script> tag in the document, with its
src attribute pointing to a specific query URL for the spreadsheet. Output format should be
We’ve got a feed with information about certain cells (range
:Bn, where n is a row index). As the sheet contains 159 quotations, in order to provide a different one daily we compute that row index as the current day in year modulus total number of rows.
<div> would also work —in fact, any container element with class
cite). For other blogging platforms the same effect could be achieved by directly editing the template, or by some other means which I leave as exercise for the reader.