8

無論如何,我可以使用PHP將數據寫入Google Docs Spreadsheet,除了Zend庫嗎?我嘗試過Zend庫,雖然它很有幫助,但我希望能夠指定要寫入的特定行和列,而不是寫入指定列的最後一行。從我所看到的,Zend庫不具備這一功能。使用PHP寫入Google文檔電子表格

任何鏈接或代碼將不勝感激!

回答

6

我希望任何人這一個有用的..

// load Zend Gdata libraries 
require_once 'Zend/Loader.php'; 
Zend_Loader::loadClass('Zend_Gdata_Spreadsheets'); 
Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); 

// set credentials for ClientLogin authentication 
$user = "[email protected]"; 
$pass = "somepass"; 

try { 
    // connect to API 
    $service = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME; 
    $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service); 
    $service = new Zend_Gdata_Spreadsheets($client); 

    // set target spreadsheet and worksheet 
    $ssKey = 'ssid'; 
    $wsKey = 'wsid'; 

    // update cell at row 6, column 5 
    $entry = $service->updateCell('6', '5', 'Hello, world', $ssKey, $wsKey); 
    echo 'Updated cell ' . $entry->getTitle()->getText() . ''; 

    // clear cell at row 1, column 1 
    $entry = $service->updateCell('1', '1', '', $ssKey, $wsKey); 
    echo 'Cleared cell ' . $entry->getTitle()->getText(); 

} catch (Exception $e) { 
    die('ERROR: ' . $e->getMessage()); 
} 
+0

我得到'錯誤:預期的響應代碼200,得到400在這個URL的電子表格找不到。確保您擁有正確的網址,並且電子表格的所有者尚未將其刪除。' –

+0

如何獲得這個Zend庫? –

+0

@MikeWarren你可以在這裏找到他們網站上的下載:http://www.zend.com/company/community/framework/downloads – Andrew

相關問題