Exemplo n.º 1
0
        public void TestDefaultPalette()
        {
            PaletteRecord palette = new PaletteRecord();

            //make sure all the HSSFColor constants match
            Hashtable colors = HSSFColor.GetIndexHash();
            IEnumerator indexes = colors.Keys.GetEnumerator();
            while (indexes.MoveNext())
            {
                int index = (int)indexes.Current;
                HSSFColor c = (HSSFColor)colors[index];
                byte[] rgbTriplet = c.GetTriplet();
                byte[] paletteTriplet = palette.GetColor((short)index);
                String msg = "Expected HSSFColor constant to match PaletteRecord at index 0x"
                    + NPOI.Util.StringUtil.ToHexString(c.Indexed);
                Assert.AreEqual(rgbTriplet[0], paletteTriplet[0] & 0xff,msg);
                Assert.AreEqual(rgbTriplet[1], paletteTriplet[1] & 0xff,msg);
                Assert.AreEqual(rgbTriplet[2], paletteTriplet[2] & 0xff,msg);
            }
        }
Exemplo n.º 2
0
        public void TestCustomPalette()
        {
            //reading sample xls
            HSSFWorkbook book = HSSFTestDataSamples.OpenSampleWorkbook("Simple.xls");

            //creating custom palette
            HSSFPalette palette = book.GetCustomPalette();
            palette.SetColorAtIndex((short)0x12, (byte)101, (byte)230, (byte)100);
            palette.SetColorAtIndex((short)0x3b, (byte)0, (byte)255, (byte)52);

            //writing to disk; reading in and verifying palette
            string tmppath = TempFile.GetTempFilePath("TestCustomPalette", ".xls");
            FileStream fos = new FileStream(tmppath, FileMode.OpenOrCreate);
            book.Write(fos);
            fos.Close();

            FileStream fis = new FileStream(tmppath, FileMode.Open,FileAccess.Read);
            book = new HSSFWorkbook(fis);
            fis.Close();

            palette = book.GetCustomPalette();
            HSSFColor color = palette.GetColor(HSSFColor.CORAL.index);  //unmodified
            Assert.IsNotNull(color, "Unexpected null in custom palette (unmodified index)");
            short[] expectedRGB = HSSFColor.CORAL.triplet;
            short[] actualRGB = color.GetTriplet();
            String msg = "Expected palette position to remain unmodified";
            Assert.AreEqual(expectedRGB[0], actualRGB[0], msg);
            Assert.AreEqual(expectedRGB[1], actualRGB[1], msg);
            Assert.AreEqual(expectedRGB[2], actualRGB[2], msg);

            color = palette.GetColor((short)0x12);
            Assert.IsNotNull(color, "Unexpected null in custom palette (modified)");
            actualRGB = color.GetTriplet();
            msg = "Expected palette modification to be preserved across save";
            Assert.AreEqual((short)101, actualRGB[0], msg);
            Assert.AreEqual((short)230, actualRGB[1], msg);
            Assert.AreEqual((short)100, actualRGB[2], msg);
        }
Exemplo n.º 3
0
 public void SetUp()
 {
     palette = new PaletteRecord();
     hssfPalette = new HSSFPalette(palette);
 }
Exemplo n.º 4
0
 public HSSFPalette(PaletteRecord palette)
 {
     this.palette = palette;
 }