You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于displayNewAppointmentForm API不支持HTML正文的技术问询

关于Office.context.mailbox.displayNewAppointmentForm的HTML正文支持情况及替代方案

当前API实际支持情况

截至2024年,Office.context.mailbox.displayNewAppointmentForm的body参数仍然仅支持纯文本。尽管微软文档标注该参数适用于AppointmentForm,但实际在Outlook Web端等环境中,传入的HTML内容会被直接解析为纯文本显示,这一问题从2020年至今尚未得到官方修复,文档描述与实际功能存在滞后性。

可行替代方案

方案1:先创建约会,再通过API插入HTML正文

通过两步操作实现:先调用displayNewAppointmentForm创建基础约会框架,再监听约会窗口激活事件,使用body.setAsync方法插入HTML格式的正文内容。

示例代码:

// 初始化基础约会参数
const start = new Date();
const end = new Date();
end.setHours(start.getHours() + 1);

// 创建新约会(临时设置纯文本占位符)
Office.context.mailbox.displayNewAppointmentForm({
  requiredAttendees: ["bob@contoso.com"],
  optionalAttendees: ["sam@contoso.com"],
  start: start,
  end: end,
  location: "Home",
  subject: "meeting",
  resources: ["projector@contoso.com"],
  body: "加载中..."
});

// 监听项目切换事件,确保约会对象已加载
Office.context.mailbox.addHandlerAsync(Office.EventType.ItemChanged, () => {
  const currentItem = Office.context.mailbox.item;
  if (currentItem.itemType === Office.MailboxEnums.ItemType.Appointment) {
    const htmlContent = '<b>Test Appointment</b><br><br>Test appointment body.';
    // 插入HTML正文
    currentItem.body.setAsync(
      htmlContent,
      { coercionType: Office.CoercionType.Html },
      (result) => {
        if (result.status !== Office.AsyncResultStatus.Succeeded) {
          console.error('设置HTML正文失败:', result.error.message);
        }
      }
    );
  }
});

方案2:使用Outlook深度链接直接生成约会

通过构造Outlook Web端的深度链接,直接打开带HTML正文的新约会页面。需要注意对HTML内容进行URL编码,避免格式错误。

示例URL(需替换参数值并编码):

https://outlook.office.com/calendar/0/deeplink/compose?path=/calendar/action/compose&subject=meeting&start=2024-05-20T10:00:00&end=2024-05-20T11:00:00&location=Home&to=bob@contoso.com&cc=sam@contoso.com&body=%3Cb%3ETest%20Appointment%3C%2Fb%3E%3Cbr%3E%3Cbr%3ETest%20appointment%20body.

这种方式无需依赖Office.js,但参数格式可能随微软更新调整,且仅适用于Outlook Web端。

内容的提问来源于stack exchange,提问作者KimYu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 12:42:36