Beispiel #1
0
        private short GetXLColour(HSSFWorkbook workbook, System.Drawing.Color SystemColour)
        {
            short       s         = 0;
            HSSFPalette XlPalette = workbook.GetCustomPalette();

            NPOI.HSSF.Util.HSSFColor XlColour = XlPalette.FindColor(SystemColour.R, SystemColour.G, SystemColour.B);
            if (XlColour == null)
            {
                if (NPOI.HSSF.Record.PaletteRecord.STANDARD_PALETTE_SIZE < 255)
                {
                    if (NPOI.HSSF.Record.PaletteRecord.STANDARD_PALETTE_SIZE < 64)
                    {
                        //NPOI.HSSF.Record.PaletteRecord.STANDARD_PALETTE_SIZE= 64;
                        //NPOI.HSSF.Record.PaletteRecord.STANDARD_PALETTE_SIZE += 1;
                        XlColour = XlPalette.AddColor(SystemColour.R, SystemColour.G, SystemColour.B);
                    }
                    else
                    {
                        XlColour = XlPalette.FindSimilarColor(SystemColour.R, SystemColour.G, SystemColour.B);
                    }
                    s = XlColour.Indexed;
                }
            }
            else
            {
                s = XlColour.Indexed;
            }

            return(s);
        }
Beispiel #2
0
 public void Compare(HSSFColor expected, HSSFColor palette)
 {
     short[] s1 = expected.GetTriplet();
     short[] s2 = palette.GetTriplet();
     Assert.AreEqual(s1[0], s2[0]);
     Assert.AreEqual(s1[1], s2[1]);
     Assert.AreEqual(s1[2], s2[2]);
 }
Beispiel #3
0
 public void Compare(HSSFColor expected, HSSFColor palette)
 {
     Assert.AreEqual(expected.GetHexString(), palette.GetHexString());
 }
Beispiel #4
0
        public static string GetColor(HSSFColor color)
        {
            StringBuilder stringBuilder = new StringBuilder(7);
            stringBuilder.Append('#');
            foreach (short s in color.GetTriplet())
            {
                //if (s < 10)
                //    stringBuilder.Append('0');

                stringBuilder.Append(s.ToString("x2"));
            }
            string result = stringBuilder.ToString();

            if (result.Equals("#ffffff"))
                return "white";

            if (result.Equals("#c0c0c0"))
                return "silver";

            if (result.Equals("#808080"))
                return "gray";

            if (result.Equals("#000000"))
                return "black";

            return result;
        }
Beispiel #5
0
        private static int GetIndex2(HSSFColor color)
        {
            FieldInfo f = color.GetType().GetField("Index2", BindingFlags.Static | BindingFlags.Public);
            if (f == null)
            {
                return -1;
            }

            short s = (short)f.GetValue(color);
            return Convert.ToInt32(s);
        }
Beispiel #6
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);
        }
 public void Compare(HSSFColor expected, HSSFColor palette)
 {
     byte[] s1 = expected.RGB;
     byte[] s2 = palette.RGB;
     Assert.AreEqual(s1[0], s2[0]);
     Assert.AreEqual(s1[1], s2[1]);
     Assert.AreEqual(s1[2], s2[2]);
 }
Beispiel #8
0
        private HSSFCellStyle GetCellStyle(HSSFWorkbook workbook, string formatString, HSSFColor colour)
        {
            HSSFCellStyle cellStyle;
            cellStyle = workbook.CreateCellStyle() as HSSFCellStyle;

            HSSFDataFormat dataFormat = workbook.CreateDataFormat() as HSSFDataFormat;

            if (cellStyle != null)
            {
                if (dataFormat != null) cellStyle.DataFormat = dataFormat.GetFormat(formatString);
                cellStyle.FillForegroundColor = colour.Indexed;
                cellStyle.FillPattern = FillPattern.SolidForeground;

                //cellStyle.BorderBottom = BorderStyle.THIN;
                //cellStyle.BorderLeft = BorderStyle.THIN;
                //cellStyle.BorderRight = BorderStyle.THIN;
                //cellStyle.BorderTop = BorderStyle.THIN;

            }
            return cellStyle;
        }
Beispiel #9
0
 IndexedColors(int idx, HSSFColor color)
 {
     index = idx;
     this.hssfColor = color;
 }