PHP : Zend Gdata による Google ドキュメントのセルの更新


  デモ用のコードを解りやすく




Zend Framework
Zend Framework: Downloads
Zend Framework: Documentation: Google Spreadsheets の使用法

Google ドキュメントで最も必要な処理は、準備したデータを取り出す処理と更新する処理になります。取り出すほうは、JavaScript で、比較的簡単なのですが、更新のサンプルがやたらと難解だったので書きなおしました。


関連する記事

JS : Google Visualization : Table : Googleドキュメントを使ったテーブルの作成



<?
//**********************************************************
// Zend Gdata による Google ドキュメントのセルの更新
// 
// ※ demos\Zend\Gdata\Spreadsheet-ClientLogin.php
// ※ を書きなおしたものです
// 
// include_path="インストールパス\ZendFramework\library"
// Windows : extension=php_openssl.dll が必要です
//**********************************************************
header( "Content-Type: text/html; Charset=utf-8" );
header( "pragma: no-cache" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
header( "Cache-control: no-cache" );

require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Spreadsheets');
Zend_Loader::loadClass('Zend_Gdata_App_AuthException');
Zend_Loader::loadClass('Zend_Http_Client');

//**********************************************************
// https が使用されます。
//**********************************************************
$email = "メールアド゜レス";
$password = "パスワード";
$target_no = 0;
// 更新するセルの位置
$row = 1;
$col = 1;
// 更新するセルの値
$inputValue = "lightbox";

//**********************************************************
// コンストラクタで行われていた処理
// ※ 接続
//**********************************************************
try {
	$client = Zend_Gdata_ClientLogin::getHttpClient(
		$email,
		$password,
		Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME
	);
}
catch (Zend_Gdata_App_AuthException $ae) {
  exit("Error: ". $ae->getMessage() ."\n資格情報が必要です\n");
}

$gdClient	= new Zend_Gdata_Spreadsheets($client);
$currKey	= '';
$currWkshtId	= '';
$listFeed	= '';
$rowCount	= 0;
$columnCount	= 0;

//**********************************************************
// promptForSpreadsheet( Spreadsheet の選択 )
//**********************************************************
$feed = $gdClient->getSpreadsheetFeed();

// $feed の表示
$targetEntry1 = null;
$i = 0;
foreach($feed->entries as $entry) {
	if ($entry instanceof Zend_Gdata_Spreadsheets_CellEntry) {
		print $entry->title->text
			 .' '. $entry->content->text . " : CellEntry<br />\n";
	}
	else if ($entry instanceof Zend_Gdata_Spreadsheets_ListEntry) {
		print $i .' '. $entry->title->text
			 .' | '. $entry->content->text . " : ListEntry<br />\n";
	}
	else {
		// ここが使われています
//		print $i .' '. $entry->title->text . " : title<br />\n";
		$targetEntry1[] = array($entry->title->text,$i);
	}
	$i++;
}

// タイトルでソートして表示
// この順序を使用して更新します
sort($targetEntry1);
foreach($targetEntry1 as $entry) {
	print $entry[1] .' '. $entry[0] . " : title<br />\n";
}

print "feed の数 : $i<br /><br />\n";

print "対象データ番号 : $target_no<br />\n";
print "対象データ : " . $feed->entries[$targetEntry1[$target_no][1]]->id->text . "<br />\n";

// キーとして保存
$currKey = explode('/', $feed->entries[$targetEntry1[$target_no][1]]->id->text);
$currKey = $currKey[5];

print "currKey : $currKey<br />\n";
print "<br />\n";


//**********************************************************
// promptForWorksheet( Worksheet の選択 )
//**********************************************************
$query = new Zend_Gdata_Spreadsheets_DocumentQuery();

// 選択した Spreadsheet
$query->setSpreadsheetKey($currKey);

$feed = $gdClient->getWorksheetFeed($query);
// $feed の表示
$i = 0;
foreach($feed->entries as $entry) {
	if ($entry instanceof Zend_Gdata_Spreadsheets_CellEntry) {
		print $entry->title->text
			 .' '. $entry->content->text . " : CellEntry<br />\n";
	}
	else if ($entry instanceof Zend_Gdata_Spreadsheets_ListEntry) {
		print $i .' '. $entry->title->text
			 .' | '. $entry->content->text . " : ListEntry<br />\n";
	}
	else {
		// ここが使われています
		print $i .' '. $entry->title->text . " : title<br />\n";
	}
	$i++;
}

print "feed の数 : $i<br /><br />\n";

print "先頭データ : " . $feed->entries[0]->id->text . "<br />\n";

// IDとして保存
$currWkshtId = explode('/', $feed->entries[0]->id->text);
$currWkshtId = $currWkshtId[8];

print "currWkshtId : $currWkshtId<br />\n";
print "<br />\n";

//**********************************************************
// セルの更新
//**********************************************************
$entry = $gdClient->updateCell(
	$row,
	$col,
	$inputValue,
	$currKey,
	$currWkshtId
);
if ($entry instanceof Zend_Gdata_Spreadsheets_CellEntry) {
	print "更新が成功しました<br />\n";
	print "行 : $row, カラム : $col, 値 : $inputValue<br />\n";
}
print "<br />\n";


?>
OK














yahoo  google  MSDN  MSDN(us)  WinFAQ  Win Howto  tohoho  ie_DHTML  vector  wdic  辞書  天気 


[sh_google]
CCBot/2.0 (https://commoncrawl.org/faq/)
23/10/03 16:37:13
InfoBoard Version 1.00 : Language=Perl

1 BatchHelper COMprog CommonSpec Cprog CprogBase CprogSAMPLE CprogSTD CprogSTD2 CprogWinsock Cygwin GameScript HTML HTMLcss InstallShield InstallShieldFunc JScript JScriptSAMPLE Jsfuncs LLINK OldProg OracleGold OracleSilver PRO PRObrowser PROc PROconePOINT PROcontrol PROftpclient PROjscript PROmailer PROperl PROperlCHAT PROphp PROphpLesson PROphpLesson2 PROphpLesson3 PROphpfunction PROphpfunctionArray PROphpfunctionMisc PROphpfunctionString PROsql PROvb PROvbFunction PROvbString PROvbdbmtn PROvbonepoint PROwebapp PROwin1POINT PROwinSYSTEM PROwinYOROZU PROwindows ProjectBoard RealPHP ScriptAPP ScriptMaster VBRealtime Vsfuncs a1root access accreq adsi ajax amazon argus asp aspSample aspVarious aspdotnet aw2kinst cappvariety centura ckeyword classStyle cmaterial cmbin cmdbapp cmenum cmlang cmlistbox cmstd cmstdseed cmtxt cs daz3d db dbCommon dbaccess dnettool dos download flex2 flex3 flex4 framemtn framereq freeWorld freesoft gimp ginpro giodownload google hdml home hta htmlDom ie9svg install java javaSwing javascript jetsql jquery jsp jspTest jspVarious lightbox listasp listmsapi listmsie listmsiis listmsnt listmspatch listmsscript listmsvb listmsvc memo ms msde mysql netbeans oraPlsql oracle oracleWiper oraclehelper orafunc other panoramio pear perl personal pgdojo pgdojo_cal pgdojo_holiday pgdojo_idx pgdojo_ref pgdojo_req php phpVarious phpguide plsql postgres ps r205 realC realwebapp regex rgaki ruby rule sboard sc scprint scquest sdb sdbquest seesaa setup sh_Imagick sh_canvas sh_dotnet sh_google sh_tool sh_web shadowbox shgm shjquery shvbs shweb sjscript skadai skywalker smalltech sperl sqlq src systemdoc tcpip tegaki three toolbox twitter typeface usb useXML vb vbdb vbsfunc vbsguide vbsrc vpc wcsignup webanymind webappgen webclass webparts webtool webwsh win8 winofsql wmi work wp youtube