Simple Google Spreadsheet Loader for PHP and Ajax

Download .zip Download .tar.gz View on GitHub


Simple Google Spreadsheet Loader for PHP and Ajax


  • Load Google Spreadsheet and parse it to easy-to-read object data
  • Save it as cache file
  • Having an interface for Ajax or JSONP

Basic Usage

Create Spreadsheet

Example :

name age:integer email active:bool
john 18 true
tom 21 false
  • First row must be header consists of field name
  • If field name has data type (as :string), PHP try to juggle value to the type
    (If not set, value will be output as string)

Get Spreadsheet ID

Get your spreadsheet id from URL

  1. Open "File" > "Publish to the web" dialog
  2. In "Get a link to the published data" section, select "RSS"
  3. You can get url like below

Ths string "XXxxxxXXXxxxXxXxxxxXxxxxxXXXxXXXxXxxXXXXXXXx/yyY" is used as your sheet's ID

Load it

require "the/path/to/Ghostsheet.php";
$gs = new Ghostsheet(array(
    "cacheDir" => "./gscache/"
$data = $gs->load("XXxxxxXXXxxxXxXxxxxXxxxxxXXXxXXXxXxxXXXXXXXx/yyY");

Now, $data has array consists of spreadsheet contents.

    "id" => "",
    "title" => "mysheet", // your sheet's name
    "updated" => "2013-05-28T10:37:51.771Z",
    "items" => array(
        array("name" => "John", "age" => 18, "email" => "", "active" => true),


Ghostsheet has an interface for AJAX request.

# ajax.php
$gs = new Ghostsheet();

This will respond with JSON for the passed parameter. If no arguments, this uses $_GET as default.

Example for jQuery :

$.getJSON("ajax.php", {id : "XXxxxxXXXxxxXxXxxxxXxxxxxXXXxXXXxXxxXXXXXXXx/yyY", cache : false})
    var items = data.items;


Configure options with config() or set().

$gs->set("cacheDir", "./mycache/");
$gs->config(array("timeout", 60));


» Learn More About Ghostsheet

Change Log

» Change Log