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