SharePoint Online文本列中斜杠设置加粗/变色的实现方法
你可以通过SharePoint原生的**列格式化(Column Formatting)**功能实现,无需额外开发,操作步骤和代码示例如下:
操作步骤
- 打开目标SharePoint列表,点击顶部齿轮图标进入「列表设置」。
- 在「列」板块找到需要修改的文本列,点击列名进入列设置页面。
- 滚动到页面底部,点击「格式化此列」选项。
- 在弹出的格式化面板中,切换到「高级」模式,清空默认代码,粘贴下方对应样式的JSON代码。
- 点击「保存」,返回列表即可看到效果。
样式代码示例
方案1:将斜杠加粗
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "innerHtml": "=replace(@currentField, '/', '<strong>/</strong>')", "style": { "white-space": "pre-wrap" } }
方案2:将斜杠设置为指定颜色(示例为红色)
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "innerHtml": "=replace(@currentField, '/', '<span style=\"color:red;\">/</span>')", "style": { "white-space": "pre-wrap" } }
方案3:同时加粗+自定义颜色
如果需要同时设置加粗和颜色,修改HTML标签即可:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "innerHtml": "=replace(@currentField, '/', '<strong style=\"color:#ff5722;\">/</strong>')", "style": { "white-space": "pre-wrap" } }
补充说明
@currentField代表当前文本列的内容,replace函数会批量替换所有斜杠为带样式的HTML标签。white-space: pre-wrap用于保留文本中原有的换行和空格格式,避免内容错乱。
内容的提问来源于stack exchange,提问作者Peggy
相关产品推荐
相关产品推荐

