【问题标题】:Google Docs File propertiesGoogle 文档文件属性
【发布时间】:2018-02-13 11:13:50
【问题描述】:

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

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

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

请提供任何建议。

【问题讨论】:

  • 请用minimal and complete code sample 更新问题。什么文件属性?用户创建?或其他?有几种机制可以实现这一点,但需要更加具体。
  • var documentProperties = PropertiesService.getDocumentProperties(); documentProperties.setProperty('DAYS_TO_FETCH', '5');它用于设置文档的属性。我们想使用任何标识符访问文档中的这些属性
  • 这还不清楚。您要为文档查找哪些exact 属性?您希望它作为正文的一部分显示在文档中吗?或者你想要一个使用DriveApp 的弹出窗口?
  • 我们需要使用文档中的那些属性
  • var property = { key: 'department', value: 'Sales', 可见性: 'PUBLIC' }; Drive.Properties.insert(property, "fileid_xxxxxx");它用于插入文件属性,我们需要从文档中访问这些属性

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


【解决方案1】:

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

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 非常详细,包括代码示例。请务必查看那里以获取更详细的方法文档。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-12
    • 1970-01-01
    • 2021-02-16
    • 2017-06-01
    • 2014-02-18
    • 1970-01-01
    • 1970-01-01
    • 2022-11-04
    相关资源
    最近更新 更多