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

如何在SharePoint列表列JSON格式化的超链接中包含空格

解决SharePoint列格式化中邮件链接空格截断问题

我完全懂你这个头疼的问题——在mailto链接里内嵌带空格的SharePoint列表项URL时,总是在第一个空格处被截断,哪怕替换了%20或_x0020_也没用。这其实是因为mailto链接的body参数需要完整的URL编码,光替换空格还不够,换行符这类特殊字符也得转成编码后的格式,不然邮件客户端会错误解析链接结构。

修正后的JSON代码

这里给你两种可行的解决方案,按需选择就行:

方案1:手动编码特殊字符

直接把列表名称里的空格换成%20,同时把body里的\r\n替换为%0D%0A(这是mailto链接里标准的换行编码格式):

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "span",
      "style": {
        "padding-right": "8px"
      },
      "txtContent": "@currentField.title"
    },
    {
      "elmType": "a",
      "attributes": {
        "iconName": "Mail",
        "class": "sp-field-quickActions",
        "href": {
          "operator": "+",
          "operands": [
            "mailto:",
            "@currentField.email",
            "?subject=Task status&body=Hi ",
            "@currentField.title",
            ", Please see below link to a Shared Services Team Task which requires your attention.%0D%0A%0D%0A---%0D%0A%0D%0AClick this link for more info. https://MyCompany.sharepoint.com/sites/SharedServicesDepartment/Lists/Task%20Management%20Register/DispForm.aspx?ID=",
            "[$ID]"
          ]
        }
      }
    }
  ]
}

方案2:使用内置编码函数更省心

SharePoint列格式化自带encodeURIComponent函数,能自动编码所有特殊字符,不用手动替换,避免遗漏:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "span",
      "style": {
        "padding-right": "8px"
      },
      "txtContent": "@currentField.title"
    },
    {
      "elmType": "a",
      "attributes": {
        "iconName": "Mail",
        "class": "sp-field-quickActions",
        "href": {
          "operator": "+",
          "operands": [
            "mailto:",
            "@currentField.email",
            "?subject=Task status&body=",
            {
              "operator": "encodeURIComponent",
              "operands": [
                "Hi ",
                "@currentField.title",
                ", Please see below link to a Shared Services Team Task which requires your attention.\r\n\r\n---\r\n\r\nClick this link for more info. https://MyCompany.sharepoint.com/sites/SharedServicesDepartment/Lists/Task Management Register/DispForm.aspx?ID=",
                "[$ID]"
              ]
            }
          ]
        }
      }
    }
  ]
}

关键修改点说明

  1. 空格处理:方案1手动替换空格为%20;方案2通过编码函数自动处理所有空格和特殊字符,更稳妥。
  2. 换行符处理:方案1把\r\n换成%0D%0A;方案2的编码函数会自动转换换行符,不用手动调整。
  3. 完整编码body内容:方案2将整个body文本放入编码函数,确保所有特殊字符(空格、换行、标点等)都被正确转码,彻底避免链接截断问题。

个人更推荐方案2,后续如果body内容有变动,不用再反复手动编码特殊字符,省心不少。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.13 08:07:32