예제 #1
0
        public void SetCellStyleProperties()
        {
            IWorkbook wb = _testDataProvider.CreateWorkbook();
            ISheet    s  = wb.CreateSheet();
            IRow      r  = s.CreateRow(0);
            ICell     c  = r.CreateCell(0);

            // Add multiple border properties to cell should create a single new style
            int styCnt1 = wb.NumCellStyles;
            Dictionary <String, Object> props = new Dictionary <String, Object>();

            props.Add(CellUtil.BORDER_TOP, BorderStyle.Thin);
            props.Add(CellUtil.BORDER_BOTTOM, BorderStyle.Thin);
            props.Add(CellUtil.BORDER_LEFT, BorderStyle.Thin);
            props.Add(CellUtil.BORDER_RIGHT, BorderStyle.Thin);
            props.Add(CellUtil.ALIGNMENT, HorizontalAlignment.Center);        // try it both with a Short (deprecated)
            props.Add(CellUtil.VERTICAL_ALIGNMENT, VerticalAlignment.Center); // and with an enum
            CellUtil.SetCellStyleProperties(c, props);
            int styCnt2 = wb.NumCellStyles;

            Assert.AreEqual(styCnt1 + 1, styCnt2, "Only one additional style should have been created");

            // Add same border another to same cell, should not create another style
            c = r.CreateCell(1);
            CellUtil.SetCellStyleProperties(c, props);
            int styCnt3 = wb.NumCellStyles;

            Assert.AreEqual(styCnt3, styCnt2, "No additional styles should have been created");

            wb.Close();
        }
예제 #2
0
        public void SetFillForegroundColorBeforeFillBackgroundColorEnum()
        {
            IWorkbook wb1 = _testDataProvider.CreateWorkbook();
            ICell     A1  = wb1.CreateSheet().CreateRow(0).CreateCell(0);
            Dictionary <String, Object> properties = new Dictionary <String, Object>();

            // FIXME: Use FillPattern.BRICKS enum
            properties.Add(CellUtil.FILL_PATTERN, FillPattern.Bricks);
            properties.Add(CellUtil.FILL_FOREGROUND_COLOR, IndexedColors.Blue.Index);
            properties.Add(CellUtil.FILL_BACKGROUND_COLOR, IndexedColors.Red.Index);

            CellUtil.SetCellStyleProperties(A1, properties);
            ICellStyle style = A1.CellStyle;

            // FIXME: Use FillPattern.BRICKS enum
            Assert.AreEqual(FillPattern.Bricks, style.FillPattern, "fill pattern");
            Assert.AreEqual(IndexedColors.Blue, IndexedColors.FromInt(style.FillForegroundColor), "fill foreground color");
            Assert.AreEqual(IndexedColors.Red, IndexedColors.FromInt(style.FillBackgroundColor), "fill background color");
        }