如何使用Zend GData创建一个空的电子表格

时间:2011-07-20 16:00:09

标签: zend-framework spreadsheet gdata zend-gdata

如何使用Zends GData Library创建一个新的空电子表格?

3 个答案:

答案 0 :(得分:5)

根据Google Documents List API,要创建新的空电子表格,请执行以下操作:按照Creating a new document or file with metadata only中的说明操作。执行此操作时,请使用http://schemas.google.com/docs/2007#spreadsheet的类别术语。

使用Zend GData库,它可能如下所示:

// Load Zend library
require_once('Zend/Loader.php');
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Docs');

// Authentication
$client = Zend_Gdata_ClientLogin::getHttpClient('you@there.com', 'sunshine-', Zend_Gdata_Docs::AUTH_SERVICE_NAME);

// Get interface to Documents List API
$docs = new Zend_Gdata_Docs($client);

// Create new document
$data = new Zend_Gdata_Docs_DocumentListEntry();
$data->setCategory(
      array(new Zend_Gdata_App_Extension_Category(
              "http://schemas.google.com/docs/2007#spreadsheet",
              "http://schemas.google.com/g/2005#kind"
)));
$data->setTitle(new Zend_Gdata_App_Extension_Title("My brand new spreadsheet", null));

// Add document to your list
$doc = $docs->insertDocument($data, Zend_Gdata_Docs::DOCUMENTS_LIST_FEED_URI);

// Display document ID
print($doc->getId());

答案 1 :(得分:0)

此刻你不能这样做。

  

Spreadsheets数据API目前没有提供的方法   以编程方式创建或删除电子表格。

引自official documentation

答案 2 :(得分:0)

我是这样做的:

     $service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
     $client = Zend_Gdata_ClientLogin::getHttpClient('USERNAME', 'PASSOWRD', $service);
     $docs = new Zend_Gdata_Docs($client);

     // A file I use as a template for this [ based on the extension is the type of document that will be created] 
     // see: http://framework.zend.com/manual/en/zend.gdata.docs.html
     $fileToUpload = 'Rates-Template.xls'; 
     $newDocumentEntry =  $docs->uploadFile($fileToUpload, 'Spreadsheet Title Here',null, Zend_Gdata_Docs::DOCUMENTS_LIST_FEED_URI);