Ejemplo n.º 1
0
        private static int GetIndex2(HSSFColor color)
        {
            FieldInfo f;

            f = color.GetType().GetField("index2", BindingFlags.Static | BindingFlags.Public);
            if (f == null)
            {
                return(-1);
            }

            short s;

            try
            {
                s = (short)f.GetValue(color);
            }
            catch (ArgumentException)
            {
                throw;
            }
            catch (InvalidOperationException)
            {
                throw;
            }
            return(Convert.ToInt32(s));
        }
Ejemplo n.º 2
0
        private static Hashtable CreateColorsByIndexMap()
        {
            HSSFColor[] colors = GetAllColors();
            Hashtable   result = new Hashtable(colors.Length * 3 / 2);

            for (int i = 0; i < colors.Length; i++)
            {
                HSSFColor color = colors[i];

                int index1 = color.GetIndex();
                if (result.ContainsKey(index1))
                {
                    HSSFColor prevColor = (HSSFColor)result[index1];
                    throw new InvalidDataException("Dup color index (" + index1
                                                   + ") for colors (" + prevColor.GetType().Name
                                                   + "),(" + color.GetType().Name + ")");
                }
                result[index1] = color;
            }

            for (int i = 0; i < colors.Length; i++)
            {
                HSSFColor color  = colors[i];
                int       index2 = GetIndex2(color);
                if (index2 == -1)
                {
                    // most colors don't have a second index
                    continue;
                }
                //if (result.ContainsKey(index2))
                //{
                //if (false)
                //{ // Many of the second indexes clash
                //    HSSFColor prevColor = (HSSFColor)result[index2];
                //    throw new InvalidDataException("Dup color index (" + index2
                //            + ") for colors (" + prevColor.GetType().Name
                //            + "),(" + color.GetType().Name + ")");
                //}
                //}
                result[index2] = color;
            }
            return(result);
        }
Ejemplo n.º 3
0
        private static Hashtable CreateColorsByHexStringMap()
        {
            HSSFColor[] colors = GetAllColors();
            Hashtable   result = new Hashtable(colors.Length * 3 / 2);

            for (int i = 0; i < colors.Length; i++)
            {
                HSSFColor color = colors[i];

                String hexString = color.GetHexString();
                if (result.ContainsKey(hexString))
                {
                    throw new InvalidDataException("Dup color hexString (" + hexString
                                                   + ") for color (" + color.GetType().Name + ")");
                }
                result[hexString] = color;
            }
            return(result);
        }
Ejemplo n.º 4
0
        private static int GetIndex2(HSSFColor color)
        {

            FieldInfo f;

            f = color.GetType().GetField("index2", BindingFlags.Static | BindingFlags.Public);
            if (f == null)
            {
                return -1;
            }

            short s;
            try
            {
                s = (short)f.GetValue(color);
            }
            catch (ArgumentException)
            {
                throw;
            }
            catch (InvalidOperationException)
            {
                throw;
            }
            return Convert.ToInt32(s);
        }