Пример #1
0
        /// <summary>
        /// Gets the closest palette color of specified color.
        /// </summary>
        /// <param name="color">An <see cref="T:Dt.Xls.IExcelColor" /> instance used to locate the palette color.</param>
        /// <returns>The closest palette color</returns>
        public ExcelPaletteColor GetPaletteColor(IExcelColor color)
        {
            if (color.ColorType == ExcelColorType.Indexed)
            {
                return((ExcelPaletteColor)color.Value);
            }
            if (color.ColorType != ExcelColorType.Theme)
            {
                return(this.GetCloestColorIndex(ColorExtension.FromArgb(color.Value)));
            }
            GcColor systemColor = new GcColor();

            if (this.Theme == null)
            {
                int num = (int)color.Value;
                if ((num < 0) || (num > 11))
                {
                    return(ExcelPaletteColor.SystemWindowBackgroundColor);
                }
                switch (color.Value)
                {
                case 0:
                    systemColor = GcSystemColors.GetSystemColor(GcSystemColorIndex.Window);
                    break;

                case 1:
                    systemColor = GcSystemColors.GetSystemColor(GcSystemColorIndex.WindowText);
                    break;

                case 2:
                    systemColor = ColorExtension.FromArgb(0xeeece1);
                    break;

                case 3:
                    systemColor = ColorExtension.FromArgb(0x1f497d);
                    break;

                case 4:
                    systemColor = ColorExtension.FromArgb(0x4f81bd);
                    break;

                case 5:
                    systemColor = ColorExtension.FromArgb(0xc0504d);
                    break;

                case 6:
                    systemColor = ColorExtension.FromArgb(0x9bbb59);
                    break;

                case 7:
                    systemColor = ColorExtension.FromArgb(0x8064a2);
                    break;

                case 8:
                    systemColor = ColorExtension.FromArgb(0x4bacc6);
                    break;

                case 9:
                    systemColor = ColorExtension.FromArgb(0xf79646);
                    break;

                case 10:
                    systemColor = ColorExtension.FromArgb(0xff);
                    break;

                case 11:
                    systemColor = ColorExtension.FromArgb(0x800080);
                    break;
                }
            }
            else
            {
                int num2 = (int)color.Value;
                if ((num2 < 0) || (num2 > 11))
                {
                    return(ExcelPaletteColor.SystemWindowBackgroundColor);
                }
                systemColor = this.GetThemeColor((ColorSchemeIndex)num2);
            }
            return(this.GetCloestColorIndex(systemColor));
        }