3-17 WSP JSA颜色知多少(颜色专题精讲)学习笔记
在 WPS 表格中有很多对象都有颜色设置,如果单元格的底色、字体颜色、图形底色、轮廓颜色等都需要设置颜色,颜色有两种设置方法。我们以设置单元格底纹颜色为例。
- 索引颜色(colorlndex属性,支持 1~56 种颜色),无颜色设置:xlColorIndexNone
- RGB 颜色(Color 属性,支持 0~16777215 种颜色),RGB 颜色需要转换为一个单值颜色,公式为:=HEX2DEC(CONCAT(DEC2HEX({B;G;R})))。
一、函数解析与使用方法:
1.索引颜色:
Interior.ColorIndex使用方法:Range(a1).Interior.ColorIndex=100
Interior内部的意思
ColorIndex索引颜色的意思
100为颜色代码
xlColorIndexNone使用方法:Range("a1").Interior.ColorIndex=xlColorIndexNone;
也可以是Range("a1").Interior.ColorIndex=0;
xlColorIndexNone无颜色的意思
2.RGB转换16进制专10进制颜色
WPS中找到底纹颜色-其他-自定议-RGB颜色
RGB转换16进制专10进制颜色(请在白色区域输入RGB颜色)
公式为:=HEX2DEC(CONCAT(DEC2HEX({B;G;R})))
颜色转换:=HEX2DEC(CONCAT(DEC2HEX({96;96;250})))
颜色转换结果:6316282
JSA使用方法:Range("d4:e5").Interior.Color=6316282
二、实例演示
实例1:索引颜色56色自动生成
function 实例1(){
for(var i=1;i<=56;i++){
Sheets("实例1").Cells(i,1).Value2=i;//Cells(i,1)单元格内容=i
Sheets("实例1").Range("a"+i).Interior.ColorIndex=i;//Range("a"+i)的区域添加,单元格颜色=i
}}
function 实例1(){ for(var i=1;i<=56;i++){ Sheets("实例1").Cells(i,1).Value2=i;//Cells(i,1)单元格内容=i Sheets("实例1").Range("a"+i).Interior.ColorIndex=i;//Range("a"+i)的区域添加,单元格颜色=i }}实例2:索引颜色56色自动生成
function 实例2(){
var x=1
var y=1
for(var i=1;i<=56;i++){//循环56次
if (y<=6){//y<=6只循环6次
Sheets("实例2").Cells(x,y).Value2=i;//Cells(x,y)和Range()是一样的意思,区别是Cells(x,y)有数字表示
Sheets("实例2").Cells(x,y).Interior.ColorIndex=i;//在Cells(x,y)这个区域添加颜色i
y++
}else{
x++
var y=1
i--
}
}
}
function 实例2(){ var x=1 var y=1 for(var i=1;i<=56;i++){//循环56次 if (y<=6){//y<=6只循环6次 Sheets("实例2").Cells(x,y).Value2=i;//Cells(x,y)和Range()是一样的意思,区别是Cells(x,y)有数字表示 Sheets("实例2").Cells(x,y).Interior.ColorIndex=i;//在Cells(x,y)这个区域添加颜色i y++ }else{ x++ var y=1 i-- } } }