nodejs导出excel----exceljs (颜色对象的转换)

前言

先要弄颜色的转换,因为在后续的font-color,border-color,background-color,都会用到

颜色存的方式

export interface Color {
    /**
     * Hex string for alpha-red-green-blue e.g. FF00FF00
     */
    argb?: string;

    /**
     * Choose a theme by index
     */
    theme?: number;
}

color有三种可能,undefined,{argb:string}, { theme: 0-9}

argb

const tinytinycolor  = require('tinytinycolor');
let colorOfArgb = 'FF00FF00';
tinytinycolor(colorOfArgb ).toHexString();

tinytinycolor 是一个颜色转换包,npmjs中去搜索

theme

function colorToHex(color: {theme: number, tint: number}) {
        let res=[];
        switch(color.theme) {
            case 0:
                res = {U:170, S: 0};
                break;
            case 1:
                res = {U:170,S: 0};
                break;
            case 2:
                res = {U: 0, S: 5};
                break;
            case 3:
                res = {U: 152, S: 56};
                break;
            case 4:
                res = {U: 148, S: 151};
                break;
            case 5:
                res = {U: 17, S: 214};
                break;
            case 6:
                res = {U: 165, S: 165};
                break;
            case 7:
                res = {U: 32, S: 255};
                break;
            case 8:
                res = {U: 68, S: 114};
                break;
            case 9:
                res = {U: 112, S: 173};
                break;
            default:
                res = {U: 170, S: 0};
                break;
        }
                if(colorObj.tint > 0) {
                    return tinytinycolor({h: res[0], s: res[1], l: Math.abs(color.tint*100)}).toHexString(); 
                } else {
                    return tinytinycolor({h: res[0], s: res[1], l: Math.abs((1 + color.tint)*100)}).toHexString(); 
                }       
}

颜色值就这些

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值