grist/doc/condition-style.md
2025-07-16 12:13:39 +08:00

158 lines
7.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

作用区域有两种表达法:
1. 单个单元格集合,示例 -> A1,A5,B3
2. 连续单元格范围,示例 -> A1-D1
if(scope.include("-")){
// 分割得到范围,然后得到所有范围内的单元格集合
}else{
// 正则提取所有的单元格出来为什么要用正则的目的是为了不管用户中间用了什么分割符都能正常使用哪怕是A1A7都能判定为两个 A1和A7
}
// 循环设置集合内每个单元格条件样式
定义翻译: condition-property-item 元素
<cell expand="None" name="C1" row="1" col="3">
<cell-style font-size="10" align="center" valign="middle">
<left-border width="1" style="solid" color="0,0,0"/>
<right-border width="1" style="solid" color="0,0,0"/>
<top-border width="1" style="solid" color="0,0,0"/>
<bottom-border width="1" style="solid" color="0,0,0"/>
</cell-style>
<dataset-value dataset-name="ds" aggregate="sum" property="运货费" order="none" mapping-type="simple"></dataset-value>
<condition-property-item>
<cell-style for-condition="true" font-size="0" forecolor="237,43,43" font-family=""></cell-style>
<!--左值是表达式-->
<condition type="expression" op="Like">
<left><![CDATA[A1]]></left>
<right><![CDATA["RICAR"]]></right>
</condition>
<!--右值是平均值-->
<condition op="LessThen" join="and">
<!--low avg is LessThen, high avg is GreatThen-->
<value><![CDATA[(avg_all(C1)+1)*5]]></value>
</condition>
</condition-property-item>
<condition-property-item>
<cell-style for-condition="true" font-size="0" forecolor="237,43,43" font-family=""></cell-style>
<!--右值是当前值-->
<condition op="Is">
<value><![CDATA[TailNP(C1, 10)]]></value>
</condition>
</condition-property-item>
</cell>
默认不填就是这种
<condition op="LessThen" join="and">
<!--low avg is LessThen, high avg is GreatThen-->
<value><![CDATA[avg_all(C1)]]></value>
</condition>
填写了目标格就是这种有typeleftright
<condition type="expression" op="Like">
<left><![CDATA[A1]]></left>
<right><![CDATA["RICAR"]]></right>
</condition>
注意事项:
forecolor="188,67,67" forecolor-scope="row" font-family="" bgcolor="212,52,52" bgcolor-scope="column" 影响范围 -cope 样式名称-cope有空、row、column
1. 如果是字符串类型 需要给用户输入的 内容 加上 "" 双引号包裹起来开头为与结尾为op都是 Like"str%" 表示开头为,"%str" 表示结尾为,"%str%"表示包含;不以开头为与结尾为 op 都是 NotLike"str%" 表示不以X开头"%str" 表示不以X结尾"%str%"表示不包含
2. 字符串与数字类型的空与非空value一律翻译空值只是OP用 Empty 与 NotEmpty区分
3. 数字类型的 高于/低于平均值 op 使用 GreatThen 与 LessThen值为 avg_all(当前单元格名称)
4. 日期时间的固定日期格式仅仅接受2011-10-01 或者 2011-10-01 13:30:33(yyyy-MM-dd HH:mm:ss),值示例: try_date("2011-11-01")
5. 天范围: 0为今天, -1 昨天, 1 明天; -n 过去n天, n 未来n天OP: DayRange
6. 月的范围: 0为本月, -1 上个月, 1 下个月; -n 过去n个月, n 未来n个月OP: MonthRange
7. 季度范围: 0为本季度, -1 上个季度, 1 下个季度; -n 为过去n季度, n 为未来n季度OP: QuarterRange
8. 周范围: 0为本周, -1 上周, 1 下周; -n 过去n周, n 未来n周OP: WeekRange
9. 年范围: 0为今年, -1 去年, 1 明年; -n 过去n年, n 未来n年OP: YearRange
10. 前多少个: OP为 Is值为 TopN(当前格名称, num);值为 TopNP(当前格名称, num) 表示以百分比计算出前多少个
11. 后多少个: OP为 Is值为 TailN(当前格名称, num);值为 TailNP(当前格名称, num) 表示以百分比计算出后多少个
* Between 范围比较 start <= value <= end 模式
<condition op="Between">
<!--数字或者日期, 例如: "2022-1-1,2022-2-1", 范围以逗号分割的字符串包含start与end两个值-->
<value><![CDATA["20,50"]]></value>
</condition>
* 动态日期比较
<condition op="Equals" type="expression">
<left><![CDATA[$A2]]></left>
<right><![CDATA[date_range('Quarter', -1)]]></right>
</condition>
使用此函数 date_range('Quarter', -1) => 0 表示本季度;-1 表示上季度,以下参数皆遵循此原则
第一个参数还有 Month、Day、Week、Year月、日、周、年
* 范围比较
date_range_start('Quarter', -1) => 返回某季度的开始时间
date_range_end('Quarter', -1) => 返回某季度的结束时间
$C1 >= date_range_start('Quarter', -1) && $C1 <= date_range_end('Quarter', 1) => 在上季度与下季度之间OP Is
斑马条纹间隔色zebra-color 元素single-color 奇色double-color偶色range 作用域
<cell expand="Right" name="C2" row="2" col="3" left-cell="root">
<cell-style font-size="10" align="center" valign="middle">
<zebra-color single-color="248,248,255" double-color="253,245,230" range="C2-C3"/>
</cell-style>
<dataset-value dataset-name="ds" aggregate="group" property="货主城市" order="none" mapping-type="simple"></dataset-value>
</cell>
数据条实现:
在支持子元素 render 的元素下增加
<render class-name="com.torchdb.spreadsheet.render.ProgressBarRender"
properties-class-name="com.torchdb.spreadsheet.render.props.ProgressBarProps">
<properties>
<![CDATA[
{
"type": "Percent", // Auto, Numeric, Percent, MinMax
"defaultColor": "220,220,220",
"customMinMax": {
"min": 30,
"max": 70
},
"ranges": [
{
"min": 50, "max": 70, "color": "255,248,220"
}, ...
]
}
]]>
</properties>
</render>
heatMap: 热图
热图与数据条图共享配置逻辑,除此之外多了一个结束颜色配置项(endColor),默认颜色为起点颜色,即从一个颜色到另外一个颜色渐变范围内的格子
开启方式:显式配置 shape 属性
<render class-name="com.torchdb.spreadsheet.render.ProgressBarRender"
properties-class-name="com.torchdb.spreadsheet.render.props.ProgressBarProps">
<properties>
<![CDATA[
{
"type": "Percent", // Auto, Numeric, Percent, MinMax
"defaultColor": "220,220,220",
"endColor":"0,0,255", // 结束颜色
"shape": "HeatMap", // 热图,默认为 Bar可不配置
"customMinMax": {
"min": 30,
"max": 70
},
"ranges": [ // 范围属性不需要
{
"min": 50, "max": 70, "color": "255,248,220"
}, ...
]
}
]]>
</properties>
</render>