示例#1
0
        /// <summary>
        /// 获取自定义颜色位置
        /// </summary>
        /// <param name="workBook"></param>
        /// <param name="rgb"></param>
        /// <returns></returns>
        private static short GetCustomColor(this HSSFWorkbook workBook, string rgb)
        {
            SetOriginalRGB();
            short indexed = defaultColorIndexed;

            if (string.IsNullOrEmpty(rgb))
            {
                return(indexed);
            }
            string[] colors = rgb.Split(',');
            if (colors.Length != 3)
            {
                return(indexed);
            }
            byte red    = 0;
            byte green  = 0;
            byte blue   = 0;
            bool result = DealRGB(colors, ref red, ref green, ref blue);

            if (result == false)
            {
                return(indexed);
            }
            HSSFPalette pattern = workBook.GetCustomPalette();

            NPOI.HSSF.Util.HSSFColor hssfColor = pattern.FindColor(red, green, blue);
            if (hssfColor == null)
            {
                return(pattern.SetCustomColor(rgb, -1));
            }
            indexed = hssfColor.Indexed;
            return(indexed);
        }
示例#2
0
        /// <summary>
        /// 设置自定义颜色
        /// </summary>
        /// <param name="workBook"></param>
        /// <param name="rgb"></param>
        private static void SetCustomColor(this HSSFWorkbook workBook, string rgb)
        {
            SetOriginalRGB();

            HSSFPalette pattern = workBook.GetCustomPalette();

            pattern.SetCustomColor(rgb, -1);
        }
示例#3
0
        private static void SetCustomColor(this HSSFWorkbook workBook, IEnumerable <ColorEntity> listColor)
        {
            SetOriginalRGB();
            // 获取调色板
            HSSFPalette pattern = workBook.GetCustomPalette();
            short       indexed = 8;

            foreach (var color in listColor)
            {
                if (indexed > 63)
                {
                    indexed = 8;
                }

                short tempIndex = pattern.SetCustomColor(color.RGB, color.Index);
                if (tempIndex == -1)
                {
                    continue;
                }
                indexed = tempIndex;
                indexed++;
            }
        }
示例#4
0
        /// <summary>
        /// 低版本设置自定义颜色
        /// </summary>
        /// <param name="workBook"></param>
        /// <param name="rgbs"></param>
        private static void SetCustomColor(this HSSFWorkbook workBook, IEnumerable <string> rgbs)
        {
            SetOriginalRGB();
            // 获取调色板
            HSSFPalette pattern = workBook.GetCustomPalette();
            short       indexed = 8;

            foreach (var rgb in rgbs)
            {
                if (indexed > 63)
                {
                    indexed = 8;
                }

                short tempIndex = pattern.SetCustomColor(rgb, indexed);
                if (tempIndex == -1)
                {
                    continue;
                }
                indexed = tempIndex;
                indexed++;
            }
        }