当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] SharePoint Online:使用 PowerShell 设置列表视图格式

作者:精品下载站 日期:2024-12-14 16:00:53 浏览:12 分类:玩电脑

SharePoint Online:使用 PowerShell 设置列表视图格式


要求:使用 PowerShell 将格式设置应用于 SharePoint Online 视图。

如何将格式应用于 SharePoint Online 中的列表视图?

与列格式类似,我们也可以将格式应用于 SharePoint Online 视图。假设您想要为 SharePoint Online 列表视图应用备用行突出显示格式。以下是将格式设置应用于列表视图的步骤:

  1. 登录到您的 SharePoint Online 网站 >> 导航到列表并选择您想要设置格式的目标视图。
  2. 在“视图”下拉列表中,选择“设置当前视图格式”。

    [玩转系统] SharePoint Online:使用 PowerShell 设置列表视图格式

  3. 应用 JSON 来格式化视图。预览结果并在最终确定后点击“保存”按钮。

    [玩转系统] SharePoint Online:使用 PowerShell 设置列表视图格式

PowerShell 设置列表视图格式

好吧,使用 PowerShell 设置视图格式怎么样?以下是将格式设置应用于 SharePoint 列表视图的 PowerShell 脚本:


#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/PMO"
$ListName = "Projects"
$ViewName = "Active Projects"

$JSONFormat = @"
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
  "additionalRowClass": "=if(@rowIndex % 2 == 0,'ms-bgColor-themeLighter ms-bgColor-themeLight--hover','')"
}
"@
  
Try
{
    #Connect to site
    Connect-PnPOnline -URL $SiteURL -Interactive
      
    #Set the View Formatting
    Set-PnPView -List $ListName -Identity $ViewName -Values @{CustomFormatter =$JSONFormat} -ErrorAction Stop
    Write-host "View Format Applied Successfully!" -foregroundcolor Green
}
Catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

使用此 GitHub 资源获取社区中的列表视图格式:https://github.com/pnp/List-Formatting/tree/master/view-samples

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯