图标集

图标集(Icon Set)会根据单元格在区间内的相对位置在单元格左侧绘制一组图标,例如三色交通灯、五星评分等。

函数原型

ConditionalFormat::iconStyle(int $style): self
ConditionalFormat::reverseIcons(bool $on = true): self
ConditionalFormat::iconsOnly(bool $on = true): self

int $style

图标样式常量,参见 \Vtiful\Kernel\ConditionalFormat::ICONS_3_* / ICONS_4_* / ICONS_5_*

bool $on

开关参数,默认 truereverseIcons 反转图标顺序(高分用低分图标);iconsOnly 只显示图标,不显示单元格中的数字。

三色交通灯

$config = ['path' => './tests'];
$excel  = new \Vtiful\Kernel\Excel($config);

$cf = new \Vtiful\Kernel\ConditionalFormat();
$cf->type(\Vtiful\Kernel\ConditionalFormat::TYPE_ICON_SETS)
   ->iconStyle(\Vtiful\Kernel\ConditionalFormat::ICONS_3_TRAFFIC_LIGHTS_UNRIMMED);

$excel->fileName('tutorial.xlsx')
    ->header(['score'])
    ->data([[10], [40], [55], [60], [70], [80], [90], [100]])
    ->conditionalFormatRange('A2:A9', $cf)
    ->output();

五星评分(仅显示图标)

反转图标方向

例如三色箭头:默认是「越大越绿」,启用 reverseIcons 后变为「越小越绿」:

图标样式常量

下方常量均位于 \Vtiful\Kernel\ConditionalFormat

Last updated