Example #1
0
        public ExcelStyle AddStyle(string fontColor, string interiorColor, string id)
        {
            ExcelStyle ret = ExcelStyle.New(fontColor, interiorColor, id);

            styles.Add(id, ret);
            return(ret);
        }
Example #2
0
        /// <summary>
        /// Set the style according to text level
        /// </summary>
        /// <param name="style"></param>
        /// <param name="level"></param>
        public static void StyleAs(this ExcelStyle style, TextLevel level)
        {
            switch (level)
            {
            case TextLevel.Title:
                style.StyleAsTitle();
                break;

            case TextLevel.Heading1:
                style.StyleAsHeading1();
                break;

            case TextLevel.Heading2:
                style.StyleAsHeading2();
                break;

            case TextLevel.Heading3:
                style.StyleAsHeading3();
                break;

            case TextLevel.Normal:
                style.StyleAsNormal();
                break;
            }
        }
 protected virtual void StyleHeaderCell(ExcelStyle style)
 {
     style.Font.Bold = true;
     style.Font.Color.SetColor(Color.FromArgb(0, 0, 0));
     style.Border.Bottom.Style = ExcelBorderStyle.Thick;
     style.Border.Bottom.Color.SetColor(Color.FromArgb(33, 33, 33));
 }
Example #4
0
 private void SetTitleStyle(ExcelStyle style)
 {
     style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
     style.Fill.PatternType    = ExcelFillStyle.Solid;
     style.Fill.BackgroundColor.SetColor(Color.PowderBlue);  //rgbPowderBlue
     style.Font.Bold = true;
 }
Example #5
0
 private void SetSummaryStyle(ExcelStyle style, bool bold)
 {
     style.Fill.PatternType = ExcelFillStyle.Solid;
     style.Fill.BackgroundColor.SetColor(Color.FromArgb(215, 228, 188));
     style.HorizontalAlignment = ExcelHorizontalAlignment.Right;
     style.Font.Bold           = bold;
 }
Example #6
0
        /// <summary>
        /// 获取枚举对应CellStyle
        /// </summary>
        /// <param name="excelStyle">Excel样式枚举</param>
        /// <returns></returns>
        internal ICellStyle GetCellStyle <T>(T workbook, ExcelStyle excelStyle) where T : IWorkbook
        {
            if (StyleList.ContainsKey(excelStyle.ToString()))
            {
                return(StyleList[excelStyle.ToString()]);
            }
            ICellStyle _cellStyle = workbook.CreateCellStyle();

            _cellStyle.BorderTop    = BorderStyle.Thin;
            _cellStyle.BorderRight  = BorderStyle.Thin;
            _cellStyle.BorderLeft   = BorderStyle.Thin;
            _cellStyle.BorderBottom = BorderStyle.Thin;
            CellStyleMethod styleMethod;

            if (excelStyle.ToString().IndexOf(',') > -1)
            {
                foreach (var styleItem in excelStyle.ToString().Replace(" ", "").Split(','))
                {
                    if (Enum.IsDefined(typeof(ExcelStyle), styleItem))
                    {
                        ExcelStyle styleModel = (ExcelStyle)Enum.Parse(typeof(ExcelStyle), styleItem, true);
                        styleMethod = GetStyleMethod(styleModel);
                        styleMethod.SetCell(_cellStyle);
                    }
                }
                return(_cellStyle);
            }
            styleMethod = GetStyleMethod(excelStyle);
            styleMethod.SetCell(_cellStyle);
            StyleList.Add(excelStyle.ToString(), _cellStyle);
            return(_cellStyle);
        }
Example #7
0
 /// <summary>
 /// 绘制边框
 /// </summary>
 /// <param name="excelStyle">要绘制边框的 <see cref="ExcelWorksheet.Cells"/> 的 <see cref="ExcelBorderStyle"/></param>
 /// <param name="excelBorderStyle"><see cref="ExcelBorderStyle"/> 值</param>
 public static void DrawBorder(ExcelStyle excelStyle, ExcelBorderStyle excelBorderStyle = ExcelBorderStyle.Thin)
 {
     excelStyle.Border.Left.Style   = excelBorderStyle;
     excelStyle.Border.Right.Style  = excelBorderStyle;
     excelStyle.Border.Top.Style    = excelBorderStyle;
     excelStyle.Border.Bottom.Style = excelBorderStyle;
 }
Example #8
0
        private void applyStyleEditable(ExcelRangeBase excelCell)
        {
            ExcelStyle style = excelCell.Style;

            style.Locked = false;
            setCellColor(style, Color.Black, ColorTranslator.FromHtml("#ffffff"));
        }
Example #9
0
        private ExcelRangeBase makeCellValue(ExcelRange excelRange, int posY, int posX, object value)
        {
            ExcelRangeBase excelCell = excelRange[posY, posX];
            ExcelStyle     style     = excelCell.Style;

            if (value is String)
            {
                excelCell.Value = value.ToString();
            }
            else if (value is Int64)
            {
                excelCell.Value = ToInt64(value);
            }
            else if (value is Int32)
            {
                excelCell.Value = ToInt32(value);
            }
            else if (value is Boolean)
            {
                excelCell.Value = ToBoolean(value);
            }
            else
            {
                excelCell.Value           = ToDouble(value);
                style.Numberformat.Format = "$ ###,###,###,###,###,##0.00";
            }

            return(applyStyleDefault(excelCell));
        }
        private void AddTrackInformation(ExcelWorksheet sheet, SessionSummary sessionSummary)
        {
            StringBuilder trackInformation = new StringBuilder(sessionSummary.SessionType.ToString());

            trackInformation.Append(" at: ");
            trackInformation.Append(sessionSummary.TrackInfo.TrackName);
            if (!string.IsNullOrWhiteSpace(sessionSummary.TrackInfo.TrackLayoutName))
            {
                trackInformation.Append(" (");
                trackInformation.Append(sessionSummary.TrackInfo.TrackLayoutName);
                trackInformation.Append(") (");
                trackInformation.Append(GetSessionLength(sessionSummary));
                trackInformation.Append(")");
            }
            sheet.Cells["A1"].Value       = trackInformation.ToString();
            sheet.Cells[1, 1, 1, 9].Merge = true;
            ExcelStyle style = sheet.Cells["A1"].Style;

            style.Fill.PatternType = ExcelFillStyle.Solid;
            style.Fill.PatternColor.SetColor(System.Drawing.Color.Black);
            style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Black);
            style.VerticalAlignment   = ExcelVerticalAlignment.Center;
            style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
            style.Font.Color.SetColor(System.Drawing.Color.White);
            style.Font.Bold = true;
            style.Font.Size = 18;

            sheet.Row(1).Height = 35;
        }
        /// <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);
                }
            }
        }
Example #12
0
        public static void TestAutoLayout()
        {
            string      localFilePath = "D:\\进仓记录.xlsx";
            ExcelExport export        = new ExcelExport();
            ExcelStyle  excelStyle    = new ExcelStyle();//通常情况下,不需要修改EscelStyle

            //excelStyle.MaxColWidth = 90;
            excelStyle.MinColWidth = 80;
            excelStyle.BorderColor = Color.Black;
            excelStyle.BorderStyle = Consts.BorderStyle.Thin;

            List <Cell> list = new List <Cell>();

            list.Add(new Cell("验货室RFID进仓管控表格", "A1", "o1")
            {
                FontSize = 24, TextAlign = Consts.TextAlign.BottomCenter
            });
            list.Add(new Cell("进仓记录", "A2", "O2")
            {
                MinHeight = 40
            });
            list.Add(new Cell("鞋型名称", 0, 2));
            list.Add(new Cell("制令号", 1, 2));
            list.Add(new Cell("ART", 2, 2));
            list.Add(new Cell("季节", 3, 2));
            list.Add(new Cell("用途", 4, 2));
            list.Add(new Cell("码数", 5, 2));
            list.Add(new Cell("样品单总数量(只)", 6, 2));
            list.Add(new Cell("鞋型负责人", 7, 2));
            list.Add(new Cell("进仓日期", 8, 2));
            list.Add(new Cell("进仓数量(只)", 9, 2));
            list.Add(new Cell("进仓时间", 10, 2));
            list.Add(new Cell("加工交付人签收条码", 11, 2));
            list.Add(new Cell("加工交付时间", 12, 2));
            list.Add(new Cell("验货室人接收人条码", 13, 2));
            list.Add(new Cell("验货室人接收时间", 14, 2));

            ExcelPackage package = null;

            try
            {
                package = new ExcelPackage();
                var sheetName = "Sheet1";
                var sheet     = package.Workbook.Worksheets.Add(sheetName);
                export.Export(list, sheet, excelStyle);//不需要修改整体样式时,不需要传递excelStyle
                FileInfo f = new FileInfo(localFilePath);
                package.SaveAs(f);
                System.Diagnostics.Process.Start(localFilePath);
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (package != null)
                {
                    package.Dispose();
                }
            }
        }
Example #13
0
 private void SetHeaderStyle(ExcelStyle style)
 {
     style.Font.Name           = "Arial";
     style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
     style.Fill.PatternType    = ExcelFillStyle.Solid;
     style.Fill.BackgroundColor.SetColor(Color.FromArgb(154, 34, 34)); //rgbBrown
     style.Font.Color.SetColor(Color.White);
 }
Example #14
0
        public static double GetDefaultFontWidth(ExcelStyle style, string text)
        {
            string font       = style.Font.Name;
            int    fontSize   = (int)style.Font.Size;
            Font   stringFont = new Font(font, fontSize);

            return(GetWidth(stringFont, text) + 2.0);
        }
Example #15
0
        /// <summary>
        /// 设置样式
        /// </summary>
        /// <param name="sheet"></param>
        private void SetStyles(ExcelWorksheet sheet)
        {
            SetSheetStyle(sheet);
            ExcelStyle headStype = sheet.Cells[1, 1, 1, _columnHeadList.Count].Style;

            SetColumnHeadFontStyle(headStype.Font);
            SetColumnHeadBorderStyle(headStype.Border);
            SetColumnHeadFillStyle(headStype.Fill);
        }
Example #16
0
            public static ExcelStyle New(string fontColor, string interiorColor, string id)
            {
                ExcelStyle ret = new ExcelStyle();

                ret.FontColor     = fontColor;
                ret.InteriorColor = interiorColor;
                ret.Id            = id;
                return(ret);
            }
Example #17
0
 internal ExcelNamedStyleXml(XmlNamespaceManager NameSpaceManager, XmlNode topNode, ExcelStyles styles)
     : base(NameSpaceManager, topNode)
 {
     StyleXfId = GetXmlNodeInt(idPath);
     Name = GetXmlNode(namePath);
     BuildInId = GetXmlNodeInt(buildInIdPath);
     _styles = styles;
     _style = new ExcelStyle(styles, styles.NamedStylePropertyChange, -1, Name, _styleXfId);
 }
Example #18
0
 public Style(ExcelStyle style)
 {
     _style        = style;
     _font         = new Font(style.Font);
     _fill         = new Fill(style.Fill);
     _border       = new Border(style.Border);
     _numberFormat = new NumberFormat(style.Numberformat.Format);
     _numberFormat.OnValueChanged += NumberFormatChanged;
 }
Example #19
0
        public ExcelNamedStyleXml CreateNamedStyle(string name, ExcelStyle Template)
        {
            if (_wb.Styles.NamedStyles.ExistsKey(name))
            {
                throw new Exception(string.Format("Key {0} already exists in collection", name));
            }

            ExcelNamedStyleXml style;

            style = new ExcelNamedStyleXml(NameSpaceManager, this);
            int         xfIdCopy, positionID;
            ExcelStyles styles;

            if (Template == null)
            {
//                style.Style = new ExcelStyle(this, NamedStylePropertyChange, -1, name, 0);
                xfIdCopy   = 0;
                positionID = -1;
                styles     = this;
            }
            else
            {
                if (Template.PositionID < 0 && Template.Styles == this)
                {
                    xfIdCopy = Template.Index;

                    positionID = Template.PositionID;
                    styles     = this;
                    //style.Style = new ExcelStyle(this, NamedStylePropertyChange, Template.PositionID, name, Template.Index);
                    //style.StyleXfId = Template.Index;
                }
                else
                {
                    xfIdCopy   = Template.XfId;
                    positionID = -1;
                    styles     = Template.Styles;
                }
            }
            //Clone namedstyle
            int styleXfId = CloneStyle(styles, xfIdCopy, true);

            //Close cells style
            CellStyleXfs[styleXfId].XfId = CellStyleXfs.Count - 1;
            int xfid = CloneStyle(styles, xfIdCopy, true, true); //Always add a new style (We create a new named style here)

            CellXfs[xfid].XfId = styleXfId;
            style.Style        = new ExcelStyle(this, NamedStylePropertyChange, positionID, name, styleXfId);
            style.StyleXfId    = styleXfId;

            style.Name = name;
            int ix = _wb.Styles.NamedStyles.Add(style.Name, style);

            style.Style.SetIndex(ix);
            //style.Style.XfId = ix;
            return(style);
        }
Example #20
0
 public void SetHeaderStyle(ExcelStyle style)
 {
     style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
     style.VerticalAlignment   = ExcelVerticalAlignment.Center;
     style.Border.Right.Style  = ExcelBorderStyle.Thin;
     style.Border.Bottom.Style = ExcelBorderStyle.Thin;
     style.Font.Bold           = true;
     style.Fill.PatternType    = ExcelFillStyle.Solid;
     //style.Fill.BackgroundColor.SetColor(System.Drawing.Color.LightGray);
 }
 public static void SetStyle(this ExcelStyle Style, styleFourSide side)
 {
     if (side != null)
     {
         Style.SetStyle(side.top);
         Style.SetStyle(side.bottom);
         Style.SetStyle(side.left);
         Style.SetStyle(side.right);
     }
 }
        public ExcelStyleInstance(ObjectInstance prototype, ExcelStyle excelStyle)
            : this(prototype)
        {
            if (excelStyle == null)
            {
                throw new ArgumentNullException("excelStyle");
            }

            m_excelStyle = excelStyle;
        }
Example #23
0
        internal static CssDeclaration ToCss(this ExcelStyle excelStyle)
        {
            var css = new CssDeclaration();

            css["text-align"]       = excelStyle.HorizontalAlignment.ToCssProperty();
            css["background-color"] = excelStyle.Fill.BackgroundColor.ToHexCode();
            css.Update(excelStyle.Font.ToCss());
            css.Update(excelStyle.Border.ToCss());
            return(css);
        }
        internal ExcelNamedStyleXml(XmlNamespaceManager namespaceManager, XmlNode topNode, ExcelStyles styles) : base(namespaceManager, topNode)
        {
            StyleXfId     = GetXmlNodeInt(IdPath);
            Name          = GetXmlNodeString(NamePath);
            BuiltinId     = GetXmlNodeInt(BuiltinIdPath);
            CustomBuiltin = GetXmlNodeBool(CustomBuiltinPath);

            _styles = styles;
            Style   = new ExcelStyle(styles, styles.NamedStylePropertyChange, -1, Name, StyleXfId);
        }
Example #25
0
        private ExcelRangeBase applyStyleDefault(ExcelRangeBase excelCell)
        {
            ExcelStyle style = excelCell.Style;

            style.Locked              = true; //por defecto todas la columnas bloqueadas a edicion
            style.Font.Size           = 11;
            style.Border.Top.Style    = ExcelBorderStyle.Hair;
            style.ShrinkToFit         = true;
            style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
            setCellColor(style, Color.DimGray, ColorTranslator.FromHtml("#eaeded"));
            return(excelCell);
        }
Example #26
0
 private void AssetExcelStyle(ExcelStyle style)
 {
     Contract.Assert(style != null);
     Contract.Assert(style.FontFamily != null);
     Contract.Assert(style.MinRowHeight >= 0);
     Contract.Assert(style.MaxRowHeight > 0);
     Contract.Assert(style.MinRowHeight <= style.MaxRowHeight);
     Contract.Assert(style.MinColWidth >= 0);
     Contract.Assert(style.MaxColWidth > 0);
     Contract.Assert(style.MinColWidth <= style.MaxColWidth);
     //todo 晚上其他属性的确认
 }
Example #27
0
        internal static CssDeclaration ToCss(this ExcelStyle excelStyle)
        {
            var css = new CssDeclaration();

            css["text-align"]       = excelStyle.HorizontalAlignment.ToCssProperty();
            css["background-color"] = excelStyle.Fill.BackgroundColor.ToHexCode();
            css["overflow"]         = excelStyle.HorizontalAlignment == ExcelHorizontalAlignment.Fill ? "hidden" : null;
            css["white-space"]      = excelStyle.WrapText ? "normal" : null;
            css.Update(excelStyle.Font.ToCss());
            css.Update(excelStyle.Border.ToCss());
            return(css);
        }
        /// <summary>
        ///     Sets border style around the range.
        /// </summary>
        /// <param name="thisStyle"></param>
        /// <param name="borderStyle"></param>
        /// <param name="color"></param>
        /// <returns></returns>
        public static ExcelStyle BorderAround(this ExcelStyle thisStyle, ExcelBorderStyle borderStyle, Color color)
        {
            thisStyle.Border.Top.Style    = borderStyle;
            thisStyle.Border.Left.Style   = borderStyle;
            thisStyle.Border.Bottom.Style = borderStyle;
            thisStyle.Border.Right.Style  = borderStyle;

            thisStyle.Border.Top.Color.SetColor(color);
            thisStyle.Border.Left.Color.SetColor(color);
            thisStyle.Border.Bottom.Color.SetColor(color);
            thisStyle.Border.Right.Color.SetColor(color);
            return(thisStyle);
        }
Example #29
0
 public void ChangeRangeStyle(string range, string workSheetName, string filename, bool bold, System.Drawing.Color color, System.Drawing.Color background, float size)
 {
     using (ExcelPackage excel = new ExcelPackage(new FileInfo(filename)))
     {
         var        worksheet = getWorksheet(excel, workSheetName);
         ExcelStyle style     = worksheet.Cells[range].Style;
         style.Font.Color.SetColor(color);
         style.Fill.BackgroundColor.SetColor(color);
         style.Font.Bold = bold;
         style.Font.Size = size;
         Save(excel);
     }
 }
        private void SetStyleFromInformation(ExcelStyle rangeStyle, StyleInformation information)
        {
            rangeStyle.Font.Name           = "Arial";
            rangeStyle.Font.Size           = 10;
            rangeStyle.Numberformat.Format = information.NumberFormat;
            if (information.HorizontalAlignment.HasValue)
            {
                rangeStyle.HorizontalAlignment = information.HorizontalAlignment.Value;
            }
            if (information.VerticalAlignment.HasValue)
            {
                rangeStyle.VerticalAlignment = information.VerticalAlignment.Value;
            }
            if (information.WrapText.HasValue)
            {
                rangeStyle.WrapText = information.WrapText.Value;
            }
            if (information.FontName != null && information.FontName.Length > 0)
            {
                rangeStyle.Font.Name = information.FontName;
            }
            if (information.Bold.HasValue)
            {
                rangeStyle.Font.Bold = information.Bold.Value;
            }
            if (information.FillPattern.HasValue)
            {
                rangeStyle.Fill.PatternType = information.FillPattern.Value;

                if (information.BackgroundColour.HasValue)
                {
                    rangeStyle.Fill.BackgroundColor.SetColor(information.BackgroundColour.Value);
                }
            }
            if (information.LeftBorder.HasValue)
            {
                rangeStyle.Border.Left.Style = information.LeftBorder.Value;
            }
            if (information.TopBorder.HasValue)
            {
                rangeStyle.Border.Top.Style = information.TopBorder.Value;
            }
            if (information.RightBorder.HasValue)
            {
                rangeStyle.Border.Right.Style = information.RightBorder.Value;
            }
            if (information.BottomBorder.HasValue)
            {
                rangeStyle.Border.Bottom.Style = information.BottomBorder.Value;
            }
        }
Example #31
0
        private void AddRegions(IXLWorksheet worksheet, ExcelSheet sheet)
        {
            foreach (var dataRegion in sheet.Regions)
            {
                Throw <ArgumentNullException> .WhenObject.IsNull(() => dataRegion.Coordinates);

                _dataFormat = ExcelDataFormatFactory.GetDataFormat(dataRegion.ConfigurationDataFormat);
                _excelStyle = ExcelStyleFactory.GetStyle(dataRegion.ConfigurationExcelStyle);
                AddHeader(worksheet, dataRegion);
                AddRows(worksheet, dataRegion);
                SetStyles(worksheet, dataRegion);
                dataRegion.Coordinates.HeaderRowInitial++;
            }
        }
Example #32
0
 /// <summary>
 /// 设置字体颜色
 /// </summary>
 /// <param name="startRow">起始行</param>
 /// <param name="startColumn">起始列</param>
 /// <param name="endRow">结束行</param>
 /// <param name="endColumn">结束列</param>
 /// <param name="color">颜色索引</param>
 public void SetFontColor(int startRow, int startColumn, int endRow, int endColumn, ExcelStyle.ColorIndex color)
 {
     Range range = MyExcel.get_Range(MyExcel.Cells[startRow, startColumn], MyExcel.Cells[endRow, endColumn]);
     range.Font.ColorIndex = color;
 }
Example #33
0
 /// <summary>
 /// 设置字体样式
 /// </summary>
 /// <param name="startRow">起始行</param>
 /// <param name="startColumn">起始列</param>
 /// <param name="endRow">结束行</param>
 /// <param name="endColumn">结束列</param>
 /// <param name="isBold">是否加粗</param>
 /// <param name="isItalic">是否斜体</param>
 /// <param name="underline">下划线类型</param>
 public void SetFontStyle(int startRow, int startColumn, int endRow, int endColumn, bool isBold, bool isItalic, ExcelStyle.UnderlineStyle underline)
 {
     Range range = MyExcel.get_Range(MyExcel.Cells[startRow, startColumn], MyExcel.Cells[endRow, endColumn]);
     range.Font.Bold = isBold;
     range.Font.Italic = isItalic;
     range.Font.Underline = underline;
 }
Example #34
0
 /// <summary>
 ///设置单元格背景色及填充方式
 /// </summary>
 /// <param name="startRow">开始行</param>
 /// <param name="startColumn">开始列</param>
 /// <param name="endRow">结束行</param>
 /// <param name="endColumn">结束列</param>
 /// <param name="color">颜色索引</param>
 /// <param name="pattern">填充方式</param>
 public void CellsBackColor(int startRow, int startColumn, int endRow, int endColumn, ExcelStyle.ColorIndex color, ExcelStyle.Pattern pattern)
 {
     Range range = MyExcel.get_Range(MyExcel.Cells[startRow, startColumn], MyExcel.Cells[endRow, endColumn]);
     range.Interior.ColorIndex = color;
     range.Interior.Pattern = pattern;
 }
Example #35
0
        private static void ApplyStyle(ExcelWorksheet sheet, ExcelStyle style)
        {
            Console.WriteLine("Apply style range : " + style.Range);
            try
            {
                var range = sheet.Cells[style.Range];
                if (style.Border != null)
                {
                    var prop = range.Style.Border;
                    Action<ExcelBorderBase, ExcelBorderItem> borfunc = (bord, item) =>
                    {
                        if (bord.Color == null) return;

                        Color co = TranslateColor(bord.Color);

                        ExcelBorderStyle st = ExcelBorderStyle.None;

                        if (bord.Style != null) Enum.TryParse(bord.Style, out st);

                        if (st != ExcelBorderStyle.None)
                        {
                            if (item != null)
                            {
                                item.Style = st;
                                item.Color.SetColor(co);
                            }
                            else prop.BorderAround(st, co);
                        }

                    };

                    var border = style.Border;
                    if (border.All != null)
                    {
                        borfunc.Invoke(border.All, null);
                    }
                    else
                    {
                        if (border.Top != null) borfunc.Invoke(border.Top, prop.Top);
                        if (border.Left != null) borfunc.Invoke(border.Left, prop.Left);
                        if (border.Right != null) borfunc.Invoke(border.Right, prop.Right);
                        if (border.Bottom != null) borfunc.Invoke(border.Bottom, prop.Bottom);
                    }
                }
                if (style.Font != null)
                {
                    var prop = range.Style.Font;
                    var font = style.Font;
                    if(font.Color != null) prop.Color.SetColor(TranslateColor(font.Color));
                    prop.Name = font.Family ?? prop.Name;
                    prop.Size = font.Size > 0 ? font.Size : prop.Size;
                    prop.Bold = font.Bold;
                    prop.Italic = font.Italic;
                    prop.UnderLine = font.Underline;
                    prop.Strike = font.Strike;
                }
                if (style.Back != null)
                {
                    var ptt = ExcelFillStyle.None;
                    if (Enum.TryParse(style.Back.Pattern, out ptt) && ptt != ExcelFillStyle.None)
                    {
                        range.Style.Fill.PatternType = ptt;
                        range.Style.Fill.BackgroundColor.SetColor(TranslateColor(style.Back.Color));
                    }

                }

                /*if (style.Format != null)
                {
                    switch (style.Format.Out)
                    {
                        case ExcelOutType.DateTime:
                            //...?
                            break;
                        case ExcelOutType.Integer:
                            range.Style.Numberformat.Format = "#,##0";
                            break;
                        case ExcelOutType.Number:
                            range.Style.Numberformat.Format = "#,##0.00";
                            break;
                        case ExcelOutType.Money:
                            range.Style.Numberformat.Format = "₩ #,##0";
                            break;
                        case ExcelOutType.Normal:
                        default:
                            range.Style.Numberformat.Format = null;
                            break;
                    }
                }*/

            }
            catch (Exception E)
            {
                Console.Error.WriteLine(E.ToString());
            }
        }
Example #36
0
        /// <summary>
        /// 绘制指定单元格的边框
        /// </summary>
        /// <param name="startRow">起始行</param>
        /// <param name="startColumn">起始列</param>
        /// <param name="endRow">结束行</param>
        /// <param name="endColumn">结束列</param>
        /// <param name="isDrawTop">是否画上外框</param>
        /// <param name="isDrawBottom">是否画下外框</param>
        /// <param name="isDrawLeft">是否画左外框</param>
        /// <param name="isDrawRight">是否画右外框</param>
        /// <param name="isDrawHInside">是否画水平内框</param>
        /// <param name="isDrawVInside">是否画垂直内框</param>
        /// <param name="isDrawDown">是否画斜向下线</param>
        /// <param name="isDrawUp">是否画斜向上线</param>
        /// <param name="lineStyle">线类型</param>
        /// <param name="borderWeight">线粗细</param>
        /// <param name="color">线颜色</param>
        public void DrawCellsFrame(int startRow, int startColumn, int endRow, int endColumn,
            bool isDrawTop, bool isDrawBottom, bool isDrawLeft, bool isDrawRight,
            bool isDrawHInside, bool isDrawVInside, bool isDrawDiagonalDown, bool isDrawDiagonalUp,
            ExcelStyle.LineStyle lineStyle, ExcelStyle.BorderWeight borderWeight, ExcelStyle.ColorIndex color)
        {
            //获取画边框的单元格
            Range range = MyExcel.get_Range(MyExcel.Cells[startRow, startColumn], MyExcel.Cells[endRow, endColumn]);

            //清除所有边框
            range.Borders[XlBordersIndex.xlEdgeTop].LineStyle = ExcelStyle.LineStyle.无;
            range.Borders[XlBordersIndex.xlEdgeBottom].LineStyle = ExcelStyle.LineStyle.无;
            range.Borders[XlBordersIndex.xlEdgeLeft].LineStyle = ExcelStyle.LineStyle.无;
            range.Borders[XlBordersIndex.xlEdgeRight].LineStyle = ExcelStyle.LineStyle.无;
            range.Borders[XlBordersIndex.xlInsideHorizontal].LineStyle = ExcelStyle.LineStyle.无;
            range.Borders[XlBordersIndex.xlInsideVertical].LineStyle = ExcelStyle.LineStyle.无;
            range.Borders[XlBordersIndex.xlDiagonalDown].LineStyle = ExcelStyle.LineStyle.无;
            range.Borders[XlBordersIndex.xlDiagonalUp].LineStyle = ExcelStyle.LineStyle.无;

            //以下是按参数画边框
            if (isDrawTop)
            {
                range.Borders[XlBordersIndex.xlEdgeTop].LineStyle = lineStyle;
                range.Borders[XlBordersIndex.xlEdgeTop].Weight = borderWeight;
                range.Borders[XlBordersIndex.xlEdgeTop].ColorIndex = color;
            }

            if (isDrawBottom)
            {
                range.Borders[XlBordersIndex.xlEdgeBottom].LineStyle = lineStyle;
                range.Borders[XlBordersIndex.xlEdgeBottom].Weight = borderWeight;
                range.Borders[XlBordersIndex.xlEdgeBottom].ColorIndex = color;
            }

            if (isDrawLeft)
            {
                range.Borders[XlBordersIndex.xlEdgeLeft].LineStyle = lineStyle;
                range.Borders[XlBordersIndex.xlEdgeLeft].Weight = borderWeight;
                range.Borders[XlBordersIndex.xlEdgeLeft].ColorIndex = color;
            }

            if (isDrawRight)
            {
                range.Borders[XlBordersIndex.xlEdgeRight].LineStyle = lineStyle;
                range.Borders[XlBordersIndex.xlEdgeRight].Weight = borderWeight;
                range.Borders[XlBordersIndex.xlEdgeRight].ColorIndex = color;
            }

            if (isDrawVInside)
            {
                range.Borders[XlBordersIndex.xlInsideVertical].LineStyle = lineStyle;
                range.Borders[XlBordersIndex.xlInsideVertical].Weight = borderWeight;
                range.Borders[XlBordersIndex.xlInsideVertical].ColorIndex = color;
            }

            if (isDrawHInside)
            {
                range.Borders[XlBordersIndex.xlInsideHorizontal].LineStyle = lineStyle;
                range.Borders[XlBordersIndex.xlInsideHorizontal].Weight = borderWeight;
                range.Borders[XlBordersIndex.xlInsideHorizontal].ColorIndex = color;
            }

            if (isDrawDiagonalDown)
            {
                range.Borders[XlBordersIndex.xlDiagonalDown].LineStyle = lineStyle;
                range.Borders[XlBordersIndex.xlDiagonalDown].Weight = borderWeight;
                range.Borders[XlBordersIndex.xlDiagonalDown].ColorIndex = color;
            }

            if (isDrawDiagonalUp)
            {
                range.Borders[XlBordersIndex.xlDiagonalUp].LineStyle = lineStyle;
                range.Borders[XlBordersIndex.xlDiagonalUp].Weight = borderWeight;
                range.Borders[XlBordersIndex.xlDiagonalUp].ColorIndex = color;
            }
        }
Example #37
0
 public ExcelStyle SetHeadStyle(string fontColor, string interiorColor)
 {
     headStyle = AddStyle(fontColor, interiorColor, "head");
     return headStyle;
 }
Example #38
0
 /// <summary>
 /// 设置对齐方式
 /// </summary>
 /// <param name="startRow">开始行</param>
 /// <param name="startColumn">开始列</param>
 /// <param name="endRow">结束行</param>
 /// <param name="endColumn">结束列</param>
 /// <param name="hAlign">水平对齐</param>
 /// <param name="vAlign">垂直对齐</param>
 public void AlignmentCells(int startRow, int startColumn, int endRow, int endColumn, ExcelStyle.ExcelHAlign hAlign, ExcelStyle.ExcelVAlign vAlign)
 {
     Range range = MyExcel.get_Range(MyExcel.Cells[startRow, startColumn], MyExcel.Cells[endRow, endColumn]);
     range.VerticalAlignment = vAlign;
     range.HorizontalAlignment = hAlign;
 }
Example #39
0
 public static ExcelStyle New(string fontColor, string interiorColor, string id)
 {
     ExcelStyle ret = new ExcelStyle();
     ret.FontColor = fontColor;
     ret.InteriorColor = interiorColor;
     ret.Id = id;
     return ret;
 }