mcpField
P
power-bi-themes

power-bi-themes

github.com/julianobarbosa设计与 UI1458 次安装2 天前更新
代码仓库

关于 power-bi-themes

面向使用 pbi 的报表作者,用于管理 Power BI 报表主题和视觉对象格式的技能。无需连接 Power BI Desktop,即可检查、比较和应用主题,并设置条件格式。

主要功能

  1. 01应用 JSON 报表主题
  2. 02检查当前主题
  3. 03比较新旧主题
  4. 04设置渐变与规则格式
  5. 05以 JSON 查看格式

适用场景

  1. 01为报表应用品牌主题
  2. 02应用前审查主题变更
  3. 03根据数据值设置视觉对象格式

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/julianobarbosa/claude-code-skills --skill power-bi-themes

安装后在 Claude Code 中输入/power-bi-themes确认已加载。

详细介绍

Power BI 主题技能

管理整个报表的主题和各个视觉对象的条件格式设置。无需连接 Power BI Desktop。

应用主题

Power BI 主题是定义整个报表的颜色、字体和视觉对象默认设置的 JSON 文件。 使用以下命令应用主题:

pbi report set-theme --file corporate-theme.json

此操作会将主题文件复制到报表的 StaticResources/RegisteredResources/ 文件夹,并更新 report.json 以引用该文件。打开报表时,主题会在 Power BI Desktop 中生效。

检查当前主题

pbi report get-theme

返回:

  • base_theme -- 内置主题名称(例如 "CY24SU06")
  • custom_theme -- 已应用的自定义主题名称(如果有;否则为 null)
  • theme_data -- 自定义主题文件的完整 JSON(如果存在)

比较主题

应用新主题之前,先预览将发生的变化:

pbi report diff-theme --file proposed-theme.json

返回:

  • current / proposed -- 显示名称
  • added -- 新主题中存在、当前主题中不存在的键
  • removed -- 当前主题中存在、新主题中不存在的键
  • changed -- 两个主题中都存在但值不同的键

这有助于在提交之前发现意外的颜色变化。

主题 JSON 结构

Power BI 主题 JSON 文件通常包含:

{
  "name": "Corporate Brand",
  "dataColors": ["#0078D4", "#00BCF2", "#FFB900", "#D83B01", "#8661C5", "#00B294"],
  "background": "#FFFFFF",
  "foreground": "#252423",
  "tableAccent": "#0078D4",
  "visualStyles": { ... }
}

主要部分:

  • dataColors -- 数据系列的调色板(建议使用 6-12 种颜色)
  • background / foreground -- 页面和文本的默认设置
  • tableAccent -- 表格和矩阵的标题颜色
  • visualStyles -- 各类视觉对象的覆盖设置(字号、内边距等)

完整架构请参阅 Microsoft 主题文档。

条件格式设置

为单个视觉对象应用数据驱动的格式设置:

# Gradient background (colour scale from min to max)
pbi format background-gradient visual_abc --page page1 \
    --table Sales --column Revenue \
    --min-color "#FFFFFF" --max-color "#0078D4"

# Rules-based background (specific value triggers a colour)
pbi format background-conditional visual_abc --page page1 \
    --table Sales --column Status --value "Critical" --color "#FF0000"

# Measure-driven background (a DAX measure returns the colour)
pbi format background-measure visual_abc --page page1 \
    --table Sales --measure "Status Color"

# Inspect current formatting rules
pbi format get visual_abc --page page1

# Clear all formatting rules on a visual
pbi format clear visual_abc --page page1

工作流:为报表应用品牌样式

# 1. Create the theme file
cat > brand-theme.json << 'EOF'
{
  "name": "Acme Corp",
  "dataColors": ["#1B365D", "#5B8DB8", "#E87722", "#00A3E0", "#6D2077", "#43B02A"],
  "background": "#F8F8F8",
  "foreground": "#1B365D",
  "tableAccent": "#1B365D"
}
EOF

# 2. Preview the diff against the current theme
pbi report diff-theme --file brand-theme.json

# 3. Apply it
pbi report set-theme --file brand-theme.json

# 4. Verify
pbi report get-theme

JSON 输出

pbi --json report get-theme
pbi --json report diff-theme --file proposed.json
pbi --json format get vis1 --page p1

注意事项

  • 主题 JSON 的键区分大小写,且部分未记录: 在 dataColors 或 visualStyles 中写错一个键,会被静默忽略——不会报错,主题只会在该属性上回退到默认值。排查“主题未生效”问题之前,请与已知可用的主题 JSON 进行差异比较。
  • dataColors 数组顺序对应系列序号,而非系列名称: 重命名系列或更改图例顺序都会导致颜色轮换。请通过 visualStyles 中的度量级颜色规则锁定各系列的品牌颜色,不要依赖数组位置。
  • set-theme --file 会在命令执行时复制文件: 之后对源文件 corporate-theme.json 的修改不会同步到报表——必须重新运行 set-theme。CI 流水线必须在每次构建时重新应用主题,才能使用最新版本。
  • diff-theme 无法发现缺失键回归: 从新主题中删除键后,该键会显示在 removed 下,但 Power BI 运行时会将其视为“回退到默认值”——视觉效果看起来像主题出错,而不是缺少键。
  • 通过 format background-measure 设置条件格式时,颜色度量必须返回有效的十六进制字符串或命名颜色: 返回数字或空值会导致“未应用格式”,且不会报错。请用 IFERROR(..., "#FFFFFF") 包装度量的返回值,以便安全地处理错误。
  • format clear 会移除视觉对象上的所有格式规则,而不只是背景格式: 字体、数据标签和条件标题规则也会被移除。CLI 目前不支持选择性删除规则——唯一的工作流是先清除再重新添加。

评论

支持 Markdown