/// <summary>
        /// Sets the style.
        /// </summary>
        /// <param name="Style">The style.</param>
        /// <param name="side">The side.</param>
        public static void SetStyle(this ExcelStyle Style, styleSide side)
        {
            ExcelBorderItem bri = null;

            switch (side.direction)
            {
            case styleSideDirection.bottom:
                bri = Style.Border.Bottom;
                break;

            case styleSideDirection.left:
                bri = Style.Border.Left;
                break;

            case styleSideDirection.right:
                bri = Style.Border.Right;
                break;

            case styleSideDirection.top:
                bri = Style.Border.Top;
                break;
            }

            if (side.type != styleBorderType.unknown)
            {
                bri.Style = (ExcelBorderStyle)side.type.ToInt32();
                if (bri.Style != ExcelBorderStyle.None)
                {
                    bri.Color.SetColor(side.borderColorStatic);
                }
            }
        }
Ejemplo n.º 2
0
 public ExcelBorder(ExcelBorderItem top, ExcelBorderItem right, ExcelBorderItem bottom, ExcelBorderItem left)
 {
     Top    = top;
     Right  = right;
     Bottom = bottom;
     Left   = left;
 }
        public ExcelBorderItemInstance(ObjectInstance prototype, ExcelBorderItem excelBorderItem)
            : this(prototype)
        {
            if (excelBorderItem == null)
            {
                throw new ArgumentNullException("excelBorderItem");
            }

            m_excelBorderItem = excelBorderItem;
        }
Ejemplo n.º 4
0
 internal void ToExcelBorderItem(ExcelBorderItem excelBorderItem)
 {
     excelBorderItem.Style = Style;
     if (Style != ExcelBorderStyle.None)
     {
         if (Color != Color.Empty)
         {
             excelBorderItem.Color.SetColor(Color);
         }
     }
 }
Ejemplo n.º 5
0
        public static ExcelBorderItem Apply(this ExcelBorderItem instance, SpreadsheetBorder border)
        {
            if (border.Style is not null)
            {
                instance.Style = SpreadsheetBorderStyleMapper.Map(border.Style.Value);
            }

            if (border.Color is not null)
            {
                instance.Color.SetColor(border.Color.Value.ToDotNetColor());
            }

            return(instance);
        }
Ejemplo n.º 6
0
        internal static string ToCssProperty(this ExcelBorderItem excelBorderItem)
        {
            if (excelBorderItem != null)
            {
                string color = (excelBorderItem.Color.Rgb != null)
                    ? excelBorderItem.Color.ToHexCode()
                    : "black";

                return(excelBorderItem.Style.ToCssProperty() + " " + color);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 7
0
        private string CreateBorder(ExcelBorderItem item)
        {
            switch (item.Style)
            {
            case ExcelBorderStyle.None:
                return("");

            case ExcelBorderStyle.Thin:
                return("1px solid");

            case ExcelBorderStyle.Medium:
                return("2px solid");
            }

            return(null);
        }
Ejemplo n.º 8
0
 public static void SetStyleAndColor(
     this ExcelBorderItem border,
     ExcelBorderStyle borderStyle,
     Color?color = null)
 {
     if (border == null)
     {
         throw new ArgumentNullException(nameof(border));
     }
     border.Style = borderStyle;
     if (borderStyle != ExcelBorderStyle.None)
     {
         if (color.HasValue)
         {
             border.Color.SetColor(color.Value);
         }
         else
         {
             border.Color.SetAuto();
         }
     }
 }
Ejemplo n.º 9
0
        public BorderItem(ExcelBorderItem borderItem)
        {
            _borderItem = borderItem;
            string hexARGB = _borderItem.Color.Rgb;

            if (string.IsNullOrEmpty(hexARGB))
            {
                _color = (Color)Color.BLACK_COLOR;
            }
            else
            {
                string hexA = hexARGB.Substring(0, 2);
                string hexR = hexARGB.Substring(2, 2);
                string hexG = hexARGB.Substring(4, 2);
                string hexB = hexARGB.Substring(6, 2);
                int    a = 0, r = 0, g = 0, b = 0;
                a      = int.Parse(hexA, System.Globalization.NumberStyles.HexNumber);
                r      = int.Parse(hexR, System.Globalization.NumberStyles.HexNumber);
                g      = int.Parse(hexG, System.Globalization.NumberStyles.HexNumber);
                b      = int.Parse(hexB, System.Globalization.NumberStyles.HexNumber);
                _color = new Color(a, r, g, b);
            }
            _color.OnValueChanged += ColorChanged;
        }
Ejemplo n.º 10
0
 public BorderItem(ExcelBorderItem borderItem)
 {
     _borderItem = borderItem;
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Convert a cell border to css tyle
        /// </summary>
        /// <param name="border">Cell border</param>
        /// <returns>Cell border as css</returns>
        private string BorderToStyle(ExcelBorderItem border)
        {
            string           color = Utils.ExcelColorToHex(border.Color);
            ExcelBorderStyle type  = border.Style;
            string           size  = "1px";
            string           style = "solid";

            switch (type)
            {
            // Normal
            case ExcelBorderStyle.Thin:
            case ExcelBorderStyle.Thick:
                size = "1px";
                break;

            case ExcelBorderStyle.Dashed:
                style = "dashed";
                break;

            case ExcelBorderStyle.Dotted:
                style = "dotted";
                break;

            case ExcelBorderStyle.Double:
                style = "double";
                break;

            case ExcelBorderStyle.None:
                style = "none";
                break;

            case ExcelBorderStyle.DashDot:
                style = "dotted dashed";
                break;

            case ExcelBorderStyle.DashDotDot:
                style = "dotted dashed dotted";
                break;

            // Medium
            case ExcelBorderStyle.Medium:
                size = "2px";
                break;

            case ExcelBorderStyle.MediumDashed:
                size  = "2px";
                style = "dashed";
                break;

            case ExcelBorderStyle.MediumDashDot:
                size  = "2px";
                style = "dotted dashed";
                break;

            case ExcelBorderStyle.MediumDashDotDot:
                size  = "2px";
                style = "dotted dashed dotted";
                break;
            }

            return($"{size} {style} {color}");
        }
Ejemplo n.º 12
0
 public ExcelBorder(ExcelBorderItem borders) : this(borders, borders, borders, borders)
 {
 }
Ejemplo n.º 13
0
        public static string GetStyle(ExcelRange range)
        {
            ExcelStyle styleE    = range.Style;
            string     styleHTML = string.Empty;

            #region Font
            float fontSize = styleE.Font.Size;
            styleHTML += "font-size:" + fontSize + "px; ";

            string fontFamily = styleE.Font.Name;
            if (fontFamily == "Times New Roman")
            {
                styleHTML += "font-family:Times New Roman, Times, serif; ";
            }
            else
            {
                styleHTML += "font-family:" + fontFamily + ", Helvetica, sans-serif; ";
            }


            bool isItalic    = styleE.Font.Italic;
            bool isBold      = styleE.Font.Bold;
            bool isUnderline = styleE.Font.UnderLine;

            if (isBold && !isItalic)
            {
                styleHTML += "font-weight: bold; ";
            }
            if (isBold && isItalic)
            {
                styleHTML += "font-style: italic; font-weight: bold; ";
            }
            if (!isBold && isItalic)
            {
                styleHTML += "font-style: italic; ";
            }

            styleHTML += isUnderline ? "text-decoration: underline; " : "";
            #endregion

            #region Background and color
            string backgroundColor = styleE.Fill.BackgroundColor.Rgb;
            if (!string.IsNullOrEmpty(backgroundColor))
            {
                styleHTML += "background-color: #" + backgroundColor.Substring(2, 6) + "; ";
            }

            string color = styleE.Font.Color.Rgb;
            if (!string.IsNullOrEmpty(color))
            {
                styleHTML += "color: #" + color.Substring(2, 6) + "; ";
            }

            #endregion

            #region Align
            string HorizontalAlignment = styleE.HorizontalAlignment.ToString();
            styleHTML += "text-align:" + HorizontalAlignment + "; ";
            string VerticalAlignment = styleE.VerticalAlignment.ToString();
            string dataVertical      = "";
            switch (VerticalAlignment)
            {
            case "Center":
                dataVertical = "middle";
                break;

            case "Top":
                dataVertical = "top";
                break;

            case "Bottom":
                dataVertical = "bottom";
                break;

            default:
                dataVertical = "bottom";
                break;
            }
            styleHTML += "vertical-align:" + dataVertical + "; ";
            #endregion

            #region Border
            ExcelBorderItem b = styleE.Border.Bottom;
            if (b.Style.ToString() != "None")
            {
                styleHTML += "border-bottom: 1px solid #000000; ";
            }
            ExcelBorderItem t = styleE.Border.Top;
            if (t.Style.ToString() != "None")
            {
                styleHTML += "border-top: 1px solid #000000; ";
            }
            ExcelBorderItem l = styleE.Border.Left;
            if (l.Style.ToString() != "None")
            {
                styleHTML += "border-left: 1px solid #000000; ";
            }
            ExcelBorderItem r = styleE.Border.Right;
            if (r.Style.ToString() != "None")
            {
                styleHTML += "border-right: 1px solid #000000; ";
            }
            #endregion

            return(styleHTML);
        }