Skip to content

Instantly share code, notes, and snippets.

@nissuk
Created January 30, 2011 08:50
Show Gist options
  • Save nissuk/802700 to your computer and use it in GitHub Desktop.
Save nissuk/802700 to your computer and use it in GitHub Desktop.
Googleスプレッドシートを取得して単純なTSVとして表示する例
<?php
require_once 'Zend/Gdata.php';
require_once 'Zend/Gdata/ClientLogin.php';
require_once 'Zend/Gdata/Spreadsheets.php';
$user = ''; // GoodleアカウントのID
$pass = ''; // Googleアカウントのパスワード
$spreadsheet_key = ''; // スプレッドシートのキー(スプレッドシートのURLのkey部分)
$worksheet_id = 1; // ワークシートのID(インデックス。1-origin)
$service_name = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service_name);
$service = new Zend_Gdata_Spreadsheets($client);
$query = new Zend_Gdata_Spreadsheets_ListQuery();
$query->setSpreadsheetKey($spreadsheet_key);
$query->setWorksheetId($worksheet_id);
$feed = $service->getListFeed($query);
header('Content-Type:text/plain;charset=UTF-8');
foreach($feed as $entry) {
$row = array();
foreach ($entry->custom as $cell) {
$row[] = $cell->text;
}
echo implode("\t", $row);
echo "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment