Ejemplo n.º 1
0
        public void SetToStyle(XSSFCellStyle style)
        {
            style.SetFillForegroundColor(BackgroundColor);
            style.FillPattern = FillPattern.SolidForeground;

            style.BorderTop = BorderTop;
            style.SetTopBorderColor(BorderTopColor);
            style.BorderRight = BorderRight;
            style.SetRightBorderColor(BorderRightColor);
            style.BorderBottom = BorderBottom;
            style.SetBottomBorderColor(BorderBottomColor);
            style.BorderLeft = BorderLeft;
            style.SetLeftBorderColor(BorderLeftColor);

            style.VerticalAlignment = VerticalAlignment;
            style.Alignment         = HorizontalAlignment;
            switch (_writingMode)
            {
            case WritingModeEnum.lr_tb:
                style.Rotation = 0;
                break;

            case WritingModeEnum.tb_rl:
                style.Rotation = -90;
                break;

            case WritingModeEnum.tb_lr:
                style.Rotation = 90;
                break;

            default:
                throw new ArgumentOutOfRangeException($"Writing mode {_writingMode} is not supported");
            }
        }
Ejemplo n.º 2
0
        public void TestGetSetLeftBorderColor()
        {
            //defaults
            Assert.AreEqual(IndexedColors.Black.Index, cellStyle.LeftBorderColor);
            Assert.IsNull(cellStyle.LeftBorderXSSFColor);

            int num = stylesTable.GetBorders().Count;

            XSSFColor clr;

            //setting indexed color
            cellStyle.LeftBorderColor = (IndexedColors.BlueGrey.Index);
            Assert.AreEqual(IndexedColors.BlueGrey.Index, cellStyle.LeftBorderColor);
            clr = cellStyle.LeftBorderXSSFColor;
            Assert.IsTrue(clr.GetCTColor().IsSetIndexed());
            Assert.AreEqual(IndexedColors.BlueGrey.Index, clr.Indexed);
            //a new border was Added to the styles table
            Assert.AreEqual(num + 1, stylesTable.GetBorders().Count);

            //id of the Created border
            int borderId = (int)cellStyle.GetCoreXf().borderId;

            Assert.IsTrue(borderId > 0);
            //check Changes in the underlying xml bean
            CT_Border ctBorder = stylesTable.GetBorderAt(borderId).GetCTBorder();

            Assert.AreEqual((uint)IndexedColors.BlueGrey.Index, ctBorder.left.color.indexed);

            //setting XSSFColor
            num = stylesTable.GetBorders().Count;
            clr = new XSSFColor(Color.Cyan);
            cellStyle.SetLeftBorderColor(clr);
            Assert.AreEqual(clr.GetCTColor().ToString(), cellStyle.LeftBorderXSSFColor.GetCTColor().ToString());
            byte[] rgb = cellStyle.LeftBorderXSSFColor.RGB;
            Assert.AreEqual(Color.Cyan, Color.FromRgb((byte)(rgb[0] & 0xFF), (byte)(rgb[1] & 0xFF), (byte)(rgb[2] & 0xFF)));
            //another border was Added to the styles table
            Assert.AreEqual(num, stylesTable.GetBorders().Count);

            //passing null unsets the color
            cellStyle.SetLeftBorderColor(null);
            Assert.IsNull(cellStyle.LeftBorderXSSFColor);
        }
Ejemplo n.º 3
0
 private static void CopyBordersStyle(XSSFCell oldCell, XSSFCellStyle newCellStyle)
 {
     byte[] rgb = new byte[3] {
         0, 0, 0
     };
     newCellStyle.BorderBottom = oldCell.CellStyle.BorderBottom;
     newCellStyle.SetBottomBorderColor(new XSSFColor(rgb));
     newCellStyle.BorderLeft = oldCell.CellStyle.BorderLeft;
     newCellStyle.SetLeftBorderColor(new XSSFColor(rgb));
     newCellStyle.BorderTop = oldCell.CellStyle.BorderTop;
     newCellStyle.SetTopBorderColor(new XSSFColor(rgb));
     newCellStyle.BorderRight = oldCell.CellStyle.BorderRight;
     newCellStyle.SetRightBorderColor(new XSSFColor(rgb));
 }
Ejemplo n.º 4
0
        private void ApplyBorderStyleLeft(ICellStyle cellStyle, DocumentModel.BorderStyle borderStyleLeft)
        {
            if (borderStyleLeft == null)
            {
                return;
            }

            cellStyle.BorderLeft = this.GetBorderStyle(borderStyleLeft.Type);

            if (borderStyleLeft.Color.HasValue)
            {
                XSSFCellStyle style = cellStyle as XSSFCellStyle;
                var           color = borderStyleLeft.Color.Value;
                style.SetLeftBorderColor(new XSSFColor(new[] { color.Red, color.Green, color.Blue }));
            }
        }
        public void SetToStyle(XSSFCellStyle style)
        {
            style.SetFillForegroundColor(BackgroundColor);
            style.FillPattern = FillPattern.SolidForeground;

            style.BorderTop = BorderTop;
            style.SetTopBorderColor(BorderTopColor);
            style.BorderRight = BorderRight;
            style.SetRightBorderColor(BorderRightColor);
            style.BorderBottom = BorderBottom;
            style.SetBottomBorderColor(BorderBottomColor);
            style.BorderLeft = BorderLeft;
            style.SetLeftBorderColor(BorderLeftColor);

            style.VerticalAlignment = VerticalAlignment;
            style.Alignment         = HorizontalAlignment;
        }
Ejemplo n.º 6
0
        public void Bug58996_UsedToWorkIn3_11_ButNotIn3_13()
        {
            XSSFWorkbook  workbook  = new XSSFWorkbook();
            XSSFCellStyle cellStyle = workbook.CreateCellStyle() as XSSFCellStyle;

            cellStyle.FillForegroundColorColor = (null);
            Assert.IsNull(cellStyle.FillForegroundColorColor);
            cellStyle.FillBackgroundColorColor = (null);
            Assert.IsNull(cellStyle.FillBackgroundColorColor);
            cellStyle.FillPattern = FillPattern.NoFill;;
            Assert.AreEqual(FillPattern.NoFill, cellStyle.FillPattern);
            cellStyle.SetBottomBorderColor(null);
            Assert.IsNull(cellStyle.BottomBorderXSSFColor);
            cellStyle.SetTopBorderColor(null);
            Assert.IsNull(cellStyle.TopBorderXSSFColor);
            cellStyle.SetLeftBorderColor(null);
            Assert.IsNull(cellStyle.LeftBorderXSSFColor);
            cellStyle.SetRightBorderColor(null);
            Assert.IsNull(cellStyle.RightBorderXSSFColor);
        }
Ejemplo n.º 7
0
        private XSSFCellStyle GetCellCommonStyle(IFont font, XSSFColor color, XSSFColor foregroundColor, BorderStyle borderRight)
        {
            XSSFCellStyle style = _wb.CreateCellStyle() as XSSFCellStyle;

            style.SetFillForegroundColor(foregroundColor);
            style.FillPattern = FillPattern.SolidForeground;

            style.Alignment         = HorizontalAlignment.Center;
            style.VerticalAlignment = VerticalAlignment.Center;
            style.SetRightBorderColor(color);
            style.BorderRight = borderRight;
            style.SetLeftBorderColor(color);
            style.BorderLeft = BorderStyle.Thin;
            style.SetBottomBorderColor(color);
            style.BorderBottom = BorderStyle.Thin;
            style.SetTopBorderColor(color);
            style.BorderTop = BorderStyle.Thin;
            style.SetFont(font);
            return(style);
        }