This project has moved and is read-only. For the latest updates, please go here.

shape.Fill.Color does not work in sample6

Aug 27, 2012 at 2:16 PM

shape.Fill.Color always Color.DarkSlateGray.

1) How to change shape fill color?

2) Is it possible set shape.Border.Width to 1/4?

3) ExcelParagraph.Color does not work. always White.

 

            //Add the textbox
            var shape = ws.Drawings.AddShape("txtDesc", eShapeStyle.Rect);
            shape.SetPosition(0, 5, 5, 5);
            shape.SetSize(400, 200);

            //shape.Text = "This example demonstrates how to create various drawing objects like Pictures, Shapes and charts.\n\r\n\rThe first sheet...";
            shape.Fill.Style = eFillStyle.SolidFill;
            shape.Fill.Color = Color.Magenta;
            shape.Fill.Transparancy = 20;
            shape.Border.Fill.Style = eFillStyle.SolidFill;
            shape.Border.LineStyle = eLineStyle.LongDash;
            shape.Border.Width = 1;
            shape.Border.Fill.Color = Color.Black;
            shape.Border.LineCap = eLineCap.Round;
            shape.TextAnchoring = eTextAnchoringType.Top;
            shape.TextVertical = eTextVerticalType.Horizontal;
            shape.TextAnchoringControl=false;

            var rt = shape.RichText.Add("example");
            rt.Color = Color.Yellow;
            rt.Bold = true;

 

thanks

Aug 28, 2012 at 1:14 AM

never mind, it solved my self.

the problem is ExcelDrawingFill.Transparency property setter.

while set transparancy value Color make to Default Color.

 

ExcelDrawingFill.cs

        /// Transparancy in percent
        /// 
        public int Transparancy
        {
            get
            {
                return 100 - (GetXmlNodeInt(_fillPath + alphaPath) / 1000);
            }
            set
            {
                if (_fillTypeNode == null)
                {
                    _style = eFillStyle.SolidFill;
                    //Color = Color.FromArgb(79, 129, 189);   //Set a Default color   <== this line is the problem
                    this.Color.GetHashCode(); // dummy for insure instance. MY CODE
                }
                else if (_style != eFillStyle.SolidFill)
                {
                    throw new Exception("FillStyle must be set to SolidFill");
                }
                //CreateNode(_fillPath, false);
                SetXmlNodeString(_fillPath + alphaPath, ((100 - value) * 1000).ToString());
            }
        }

Aug 28, 2012 at 3:36 AM

ExcelDrawingBorder.Width should be double!

integer with can't set 1/4.

 

        /// <summary>
        /// Width in pixels
        /// </summary>
        public double Width
        {
            get
            {
                var lw = GetXmlNodeDoubleNull(_lineWidth);
                return lw.HasValue ? lw.Value / 12700 : 1;
            }
            set
            {
                SetXmlNodeString(_lineWidth, (value * 12700).ToString());
            }
        }
        #endregion