Skip to content

样式系统

styles 字段定义可复用的样式,供元素通过 style 属性引用。

样式定义

json
{
  "styles": {
    "myStyle": {
      // 样式属性
    }
  }
}

段落样式

属性类型说明
fontSizenumber字体大小
textColorstring文本颜色(#RRGGBB)
alignmentstring对齐方式:left / center / right / justify
boldboolean是否加粗
italicboolean是否斜体
fontNamestring字体名称
spaceBeforenumber段前间距
spaceAfternumber段后间距

示例

json
{
  "styles": {
    "title": {
      "fontSize": 24,
      "textColor": "#333333",
      "alignment": "center",
      "bold": true,
      "spaceBefore": 0,
      "spaceAfter": 20
    },
    "subtitle": {
      "fontSize": 16,
      "textColor": "#666666",
      "alignment": "center",
      "spaceAfter": 10
    },
    "body": {
      "fontSize": 12,
      "textColor": "#333333",
      "spaceAfter": 6
    }
  }
}

表格样式

属性类型说明
gridColorstring网格线颜色
headerBackgroundstring表头背景色
headerTextColorstring表头文字颜色
fontSizenumber字体大小
paddingnumber单元格内边距

示例

json
{
  "styles": {
    "table1": {
      "headerBackground": "#4472C4",
      "headerTextColor": "#FFFFFF",
      "gridColor": "#CCCCCC",
      "fontSize": 9,
      "padding": 6
    }
  }
}

在元素中引用样式

json
{
  "elements": [
    {
      "type": "text",
      "content": "使用 title 样式",
      "style": "title"
    },
    {
      "type": "table",
      "dataSource": "data",
      "style": "table1"
    }
  ]
}

下一步

Released under the MIT License.