Word.Coauthor class

在 Word 文档中代表共同创作者。

扩展

注解

API 集:WordApiDesktop 1.4

使用方

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/05-coauthoring/manage-coauthors.yaml

// Gets all coauthors currently editing the document.
await Word.run(async (context) => {
  const authors: Word.CoauthorCollection = context.document.coauthoring.authors;
  authors.load("items/name,items/emailAddress,items/isMe");
  await context.sync();

  if (authors.items.length === 0) {
    console.log("No other coauthors are currently editing this document.");
    return;
  }

  console.log(`${authors.items.length} coauthor(s) editing this document:`);
  authors.items.forEach((author: Word.Coauthor) => {
    console.log(`  ${author.name} (${author.emailAddress})${author.isMe ? " — that's you" : ""}`);
  });
});

属性

context

与对象关联的请求上下文。 这将加载项的进程连接到 Office 主机应用程序的进程。

emailAddress

获取共同创作者的电子邮件地址。

id

获取对象的唯一标识符 Coauthor

isMe

获取此作者是否代表当前用户。

locks

获取一个 CoauthoringLockCollection 对象,该对象表示文档中与此共同创作者关联的锁。

name

获取共同创作者的显示名称。

方法

load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

toJSON()

覆盖 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 (JSON.stringify反过来调用 toJSON 传递给它的对象的方法。) 虽然原始 Word.Coauthor 对象是 API 对象, toJSON 但该方法返回一个纯 JavaScript 对象, (类型化为 Word.Interfaces.CoauthorData) ,其中包含从原始对象加载的任何子属性的浅层副本。

track()

根据文档中的相应更改来跟踪对象,以便进行自动调整。 此调用是 context.trackedObjects.add (thisObject) 的简写。 如果在调用中 .sync 使用此对象,并且在“.run”批处理的顺序执行之外使用此对象,并且在设置属性或对对象调用方法时收到“InvalidObjectPath”错误,则需要在首次创建对象时将对象添加到跟踪对象集合。 如果此对象是集合的一部分,您还应跟踪父集合。

untrack()

释放与此对象关联的内存(如果先前已跟踪过)。 此调用是 context.trackedObjects.remove (thisObject) 的简写。 拥有许多跟踪对象会降低主机应用程序的速度,因此请在使用完毕后释放所添加的任何对象。 需要在内存释放生效之前调用 context.sync()

属性详细信息

context

与对象关联的请求上下文。 这将加载项的进程连接到 Office 主机应用程序的进程。

context: RequestContext;

属性值

emailAddress

获取共同创作者的电子邮件地址。

readonly emailAddress: string;

属性值

string

注解

API 集:WordApiDesktop 1.4

id

获取对象的唯一标识符 Coauthor

readonly id: string;

属性值

string

注解

API 集:WordApiDesktop 1.4

isMe

获取此作者是否代表当前用户。

readonly isMe: boolean;

属性值

boolean

注解

API 集:WordApiDesktop 1.4

locks

获取一个 CoauthoringLockCollection 对象,该对象表示文档中与此共同创作者关联的锁。

readonly locks: Word.CoauthoringLockCollection;

属性值

注解

API 集:WordApiDesktop 1.4

此 API 仅适用于旧版共同创作锁。 它不适用于新式 OneDrive 或 SharePoint 共同创作,在其中,锁定管理由服务自动处理。 对新式文档的调用将失败并 GeneralException 出现错误。

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/05-coauthoring/manage-coauthors.yaml

// Gets the locks held by each coauthor in the document.
await Word.run(async (context) => {
  const authors: Word.CoauthorCollection = context.document.coauthoring.authors;
  authors.load("items/name");
  await context.sync();

  if (authors.items.length === 0) {
    console.log("No coauthors are currently editing this document.");
    return;
  }

  authors.items.forEach((author: Word.Coauthor) => {
    author.locks.load("items/type");
  });
  await context.sync();

  authors.items.forEach((author: Word.Coauthor) => {
    const lockCount = author.locks.items.length;
    if (lockCount === 0) {
      console.log(`${author.name}: no locks`);
    } else {
      const types = author.locks.items.map((l) => l.type).join(", ");
      console.log(`${author.name}: ${lockCount} lock(s) — ${types}`);
    }
  });
});

name

获取共同创作者的显示名称。

readonly name: string;

属性值

string

注解

API 集:WordApiDesktop 1.4

方法详细信息

load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(options?: Word.Interfaces.CoauthorLoadOptions): Word.Coauthor;

参数

options
Word.Interfaces.CoauthorLoadOptions

为要加载的对象属性提供选项。

返回

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNames?: string | string[]): Word.Coauthor;

参数

propertyNames

string | string[]

指定要加载的属性的逗号分隔的字符串或字符串数组。

返回

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): Word.Coauthor;

参数

propertyNamesAndPaths

{ select?: string; expand?: string; }

propertyNamesAndPaths.select 是指定要加载的属性的逗号分隔字符串,以及 propertyNamesAndPaths.expand 指定要加载的导航属性的逗号分隔字符串。

返回

toJSON()

覆盖 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 (JSON.stringify反过来调用 toJSON 传递给它的对象的方法。) 虽然原始 Word.Coauthor 对象是 API 对象, toJSON 但该方法返回一个纯 JavaScript 对象, (类型化为 Word.Interfaces.CoauthorData) ,其中包含从原始对象加载的任何子属性的浅层副本。

toJSON(): Word.Interfaces.CoauthorData;

返回

track()

根据文档中的相应更改来跟踪对象,以便进行自动调整。 此调用是 context.trackedObjects.add (thisObject) 的简写。 如果在调用中 .sync 使用此对象,并且在“.run”批处理的顺序执行之外使用此对象,并且在设置属性或对对象调用方法时收到“InvalidObjectPath”错误,则需要在首次创建对象时将对象添加到跟踪对象集合。 如果此对象是集合的一部分,您还应跟踪父集合。

track(): Word.Coauthor;

返回

untrack()

释放与此对象关联的内存(如果先前已跟踪过)。 此调用是 context.trackedObjects.remove (thisObject) 的简写。 拥有许多跟踪对象会降低主机应用程序的速度,因此请在使用完毕后释放所添加的任何对象。 需要在内存释放生效之前调用 context.sync()

untrack(): Word.Coauthor;

返回