Google文档文件属性

时间:2018-02-13 11:13:51

标签: google-apps-script google-docs gsuite

我们需要提取文档属性并在文档中显示有任何可用于显示使用应用程序脚本的选项,或者我们可以从文档开箱即用功能中显示。

var documentProperties = PropertiesService.getDocumentProperties();
documentProperties.setProperty('DAYS_TO_FETCH', '5');`

var property = { key: 'department', value: 'Sales', visibility: 'PUBLIC' };   
Drive.Properties.insert(property, "fileid_xxxxxx");

请提供任何建议。

1 个答案:

答案 0 :(得分:0)

获取属性与设置属性相反。您可以使用问题中的内容在文档(包括电子表格或幻灯片)上设置属性:

function storeProps() {
// create the object
// Keys can also store object values
var props = { "key1": "Some string, "key2": "Another string" };

// Store the Document property, limited to the active document
PropertiesService.getDocumentProperties().setProperties(props);
}

// You can also add a single property
PropertiesService.getDocumentProperties().setProperty("key3", "Yet another string");

存储属性后,您可以使用相同的API在循环中或通过键值访问整个Property对象。

function getProps() {
  // Get the document properties
  var storedProps = PropertiesService.getDocumentProperties(); // returns an object

  // Option one: open via key if you know the key
  storedProps.getProperty(key1) // returns "Some string"

  // Option two: get the {Property} object and loop for whatever
  storedProps.getProperties() // returns { "key1": "Some string", ... }
}

The Apps Script documentation非常详细,包含代码示例。请务必在那里查看更详细的方法文档。