How to create an empty spreadsheet using Zend GData

橙三吉。 提交于 2019-12-09 23:50:43

问题


How to create a new, empty spreadsheet using Zends GData Library?


回答1:


According to the Google Documents List API, to create a new, empty spreadsheet: follow the instructions in Creating a new document or file with metadata only. When doing so, use a category term of http://schemas.google.com/docs/2007#spreadsheet.

With Zend GData library, it may look like this:

// 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());



回答2:


You cannot do this at this moment.

The Spreadsheets data API does not currently provide a way to programmatically create or delete a spreadsheet.

quote from official documentation




回答3:


Here is how I did it:

     $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);


来源:https://stackoverflow.com/questions/6764868/how-to-create-an-empty-spreadsheet-using-zend-gdata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!