用途:通过 pbi-cli 管理 Power BI 报表的全局主题与单个视觉对象的条件格式,无需连接 Power BI Desktop。
主要能力:应用主题(pbi report set-theme --file corporate-theme.json,将主题文件复制到报表的 StaticResources/RegisteredResources/ 并更新 report.json 引用,打开 Desktop 时生效);查看当前主题(pbi report get-theme,返回 base_theme、custom_theme、theme_data);对比主题差异(pbi report diff-theme --file proposed-theme.json,返回 current/proposed、added、removed、changed)。条件格式支持渐变背景(pbi format background-gradient)、规则背景(pbi format background-conditional)、度量值驱动背景(pbi format background-measure),以及查看(pbi format get)和清除(pbi format clear)。支持 pbi --json 输出。
主题 JSON 常见字段:name、dataColors、background、foreground、tableAccent、visualStyles。
限制:主题键大小写敏感且部分无文档,错误键会被静默忽略;dataColors 按系列序数而非名称映射;set-theme 在命令执行时复制文件,后续修改需重新运行,CI 每次构建都需重新应用;diff-theme 无法捕捉缺失键回归;background-measure 要求返回有效十六进制或命名颜色,建议用 IFERROR 包裹;format clear 会清除该视觉对象全部格式规则,不支持选择性删除,只能清除后重新添加。