ExcelScript.DocumentProperties interface

表示工作簿属性。

注解

示例

/**
 * This script creates a new worksheet that displays some of the document properties.
 */
function main(workbook: ExcelScript.Workbook) {
    // Get the document properties.
    const properties: ExcelScript.DocumentProperties = workbook.getProperties();

    // Create a new worksheet called "Metadata".
    const newWorksheet = workbook.addWorksheet("Metadata");
    
    // Create an array to store the string values of properties to save.
    let values: string[][] = [];
    values.push(["Creation Date", properties.getCreationDate().toString()]);
    values.push(["Author", properties.getAuthor()]);
    values.push(["Last Edited By", properties.getLastAuthor()]);
    
    // Set the property values to a range on the new worksheet.
    newWorksheet.getRange("A1:B3").setValues(values);
}

方法

addCustomProperty(key, value)

新建自定义属性或设置现有自定义属性。

deleteAllCustomProperties()

删除此集合中的所有自定义属性。

getAuthor()

工作簿的作者。

getCategory()

工作簿的类别。

getComments()

工作簿的注释。

getCompany()

工作簿的公司。

getCreationDate()

获取工作簿的创建日期。

getCustom()

获取工作簿的自定义属性的集合。

getCustomProperty(key)

按键获取自定义属性对象(不区分大小写)。 如果自定义属性不存在,则此方法返回 undefined

getKeywords()

工作簿的关键字。

getLastAuthor()

获取工作簿的最终作者。

getManager()

工作簿的经理。

getRevisionNumber()

获取工作簿的修订号。

getSubject()

工作簿的主题。

getTitle()

工作簿的标题。

setAuthor(author)

工作簿的作者。

setCategory(category)

工作簿的类别。

setComments(comments)

工作簿的注释。

setCompany(company)

工作簿的公司。

setKeywords(keywords)

工作簿的关键字。

setManager(manager)

工作簿的经理。

setRevisionNumber(revisionNumber)

获取工作簿的修订号。

setSubject(subject)

工作簿的主题。

setTitle(title)

工作簿的标题。

方法详细信息

addCustomProperty(key, value)

新建自定义属性或设置现有自定义属性。

addCustomProperty(key: string, value: any): CustomProperty;

参数

key

string

必填。 自定义属性的键,不区分大小写。 密钥限制为 255 个字符,Excel web 版 (其他平台上的较大键会自动剪裁为 255 个字符) 。

value

any

必填。 自定义属性的值。 该值限制为 255 个字符,Excel web 版 (其他平台上的较大值会自动剪裁为 255 个字符) 。

返回

示例

/**
 * This script adds a workbook-level custom property.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the property collection.
  const properties = workbook.getProperties();

  // Add a new property called "Project" with the value "FA".
  properties.addCustomProperty("Project", "FA");
}

deleteAllCustomProperties()

删除此集合中的所有自定义属性。

deleteAllCustomProperties(): void;

返回

void

getAuthor()

工作簿的作者。

getAuthor(): string;

返回

string

getCategory()

工作簿的类别。

getCategory(): string;

返回

string

getComments()

工作簿的注释。

getComments(): string;

返回

string

getCompany()

工作簿的公司。

getCompany(): string;

返回

string

getCreationDate()

获取工作簿的创建日期。

getCreationDate(): Date;

返回

Date

getCustom()

获取工作簿的自定义属性的集合。

getCustom(): CustomProperty[];

返回

getCustomProperty(key)

按键获取自定义属性对象(不区分大小写)。 如果自定义属性不存在,则此方法返回 undefined

getCustomProperty(key: string): CustomProperty | undefined;

参数

key

string

必填。 标识自定义属性对象的键。

返回

示例

/**
 * This script gets a workbook-level custom property called "Project".
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the property collection.
  const properties = workbook.getProperties();

  // Get the "Project" property.
  const project = properties.getCustomProperty("Project");

  // Show the property value in the console.
  console.log(project.getValue());
}

getKeywords()

工作簿的关键字。

getKeywords(): string;

返回

string

getLastAuthor()

获取工作簿的最终作者。

getLastAuthor(): string;

返回

string

getManager()

工作簿的经理。

getManager(): string;

返回

string

getRevisionNumber()

获取工作簿的修订号。

getRevisionNumber(): number;

返回

number

getSubject()

工作簿的主题。

getSubject(): string;

返回

string

getTitle()

工作簿的标题。

getTitle(): string;

返回

string

setAuthor(author)

工作簿的作者。

setAuthor(author: string): void;

参数

author

string

返回

void

setCategory(category)

工作簿的类别。

setCategory(category: string): void;

参数

category

string

返回

void

setComments(comments)

工作簿的注释。

setComments(comments: string): void;

参数

comments

string

返回

void

setCompany(company)

工作簿的公司。

setCompany(company: string): void;

参数

company

string

返回

void

setKeywords(keywords)

工作簿的关键字。

setKeywords(keywords: string): void;

参数

keywords

string

返回

void

setManager(manager)

工作簿的经理。

setManager(manager: string): void;

参数

manager

string

返回

void

setRevisionNumber(revisionNumber)

获取工作簿的修订号。

setRevisionNumber(revisionNumber: number): void;

参数

revisionNumber

number

返回

void

setSubject(subject)

工作簿的主题。

setSubject(subject: string): void;

参数

subject

string

返回

void

setTitle(title)

工作簿的标题。

setTitle(title: string): void;

参数

title

string

返回

void