Ejemplo n.º 1
0
 internal ExcelBorderItemXml(XmlNamespaceManager nsm, XmlNode topNode)
     : base(nsm, topNode)
 {
     if (topNode != null)
     {
         _borderStyle = GetBorderStyle(GetXmlNode("@style"));
         _color = new ExcelColorXml(nsm, topNode.SelectSingleNode(_colorPath, nsm));
         Exists = true;
     }
     else
     {
         Exists = false;
     }
 }
Ejemplo n.º 2
0
        public static void CreateCell(ExcelWorksheet sheet, int fromRow, int fromColumn, int toRow, int toColumn, double value, Color?color,
                                      float size = 11, bool isFontBold = false,
                                      ExcelHorizontalAlignment alignment = ExcelHorizontalAlignment.Center,
                                      ExcelBorderStyle borderStyle       = ExcelBorderStyle.Medium)
        {
            var cell = sheet.Cells[fromRow, fromColumn, toRow, toColumn];

            cell.Merge                     = true;
            cell.Style.Font.Size           = size;
            cell.Style.Font.Bold           = isFontBold;
            cell.Style.HorizontalAlignment = alignment;
            cell.Style.VerticalAlignment   = ExcelVerticalAlignment.Center;
            cell.Style.Border.BorderAround(borderStyle);
            cell.Style.WrapText            = true;
            cell.Style.Numberformat.Format = value % 1 == 0 ? "#,##0" : "#,##0.00";
            if (color != null)
            {
                cell.Style.Fill.PatternType = ExcelFillStyle.Solid;
                cell.Style.Fill.BackgroundColor.SetColor(color.Value);
            }
            cell.Style.Font.Name = "Courier New";
            cell.Value           = value;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sets all borders in a given range (thanks EPPlus and Codeplex)
        /// </summary>
        /// <param name="this"></param>
        /// <param name="borderStyle"></param>
        private void SetAllBorders(ExcelRange @this, ExcelBorderStyle borderStyle)
        {
            var fromRow = @this.Start.Row;
            var fromCol = @this.Start.Column;
            var toRow   = @this.End.Row;
            var toCol   = @this.End.Column;

            var numRows = toRow - fromRow + 1;
            var numCols = toCol - fromCol + 1;

            @this.Style.Border.BorderAround(borderStyle);

            for (var rowOffset = 1; rowOffset < numRows; rowOffset += 2)
            {
                var row = @this.Offset(rowOffset, 0, 1, numCols);
                row.Style.Border.BorderAround(borderStyle);
            }

            for (var colOffset = 1; colOffset < numCols; colOffset += 2)
            {
                var col = @this.Offset(0, colOffset, numRows, 1);
                col.Style.Border.BorderAround(borderStyle);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Set the border style around the range.
        /// </summary>
        /// <param name="Style">The border style</param>
        /// <param name="Color">The color of the border</param>
        public void BorderAround(ExcelBorderStyle Style, System.Drawing.Color Color)
        {
            var addr = new ExcelAddress(_address);

            if (addr.Addresses?.Count > 1)
            {
                foreach (var a in addr.Addresses)
                {
                    SetBorderAroundStyle(Style, a);
                    if (!Color.IsEmpty)
                    {
                        SetBorderColor(Color, a);
                    }
                }
            }
            else
            {
                SetBorderAroundStyle(Style, addr);
                if (!Color.IsEmpty)
                {
                    SetBorderColor(Color, addr);
                }
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 ///     Sets the border style and color of given range
 /// </summary>
 /// <param name="range"></param>
 /// <param name="style"></param>
 /// <param name="color"></param>
 /// <returns></returns>
 public static ExcelRangeBase BorderAround(this ExcelRangeBase range, ExcelBorderStyle style, Color color)
 {
     range.Style.BorderAround(style, color);
     return(range);
 }
Ejemplo n.º 6
0
        internal string SetBorderString(ExcelBorderStyle Style)
        {
            string newName = Enum.GetName(typeof(ExcelBorderStyle), Style);

            return(newName.Substring(0, 1).ToLower() + newName.Substring(1, newName.Length - 1));
        }
Ejemplo n.º 7
0
 public static ExcelRange borderTopBottom(this ExcelRange cell, ExcelBorderStyle tipoBorde = ExcelBorderStyle.Double)
 {
     cell.Style.Border.Top.Style    = tipoBorde;
     cell.Style.Border.Bottom.Style = tipoBorde;
     return(cell);
 }
Ejemplo n.º 8
0
        //https://www.cnblogs.com/tanpeng/p/6155749.html
        /// <summary>
        /// 使用EPPlus导出Excel(xlsx)
        /// </summary>
        /// <param name="sourceTable">数据源</param>
        public static Stream ExportByEPPlus(DataTable sourceTable)
        {
            using (ExcelPackage pck = new ExcelPackage())
            {
                //Create the worksheet
                string         sheetName = sourceTable.TableName.IsEmpty() ? "Sheet1" : sourceTable.TableName;
                ExcelWorksheet ws        = pck.Workbook.Worksheets.Add(sheetName);

                //Load the datatable into the sheet, starting from cell A1. Print the column names on row 1
                ws.Cells["A1"].LoadFromDataTable(sourceTable, true);

                //Format the row
                ExcelBorderStyle borderStyle = ExcelBorderStyle.Thin;
                Color            borderColor = Color.FromArgb(155, 155, 155);

                using (ExcelRange rng = ws.Cells[1, 1, sourceTable.Rows.Count + 1, sourceTable.Columns.Count])
                {
                    rng.Style.Font.Name        = "宋体";
                    rng.Style.Font.Size        = 10;
                    rng.Style.Fill.PatternType = ExcelFillStyle.Solid;
                    //Set Pattern for the background to Solid
                    rng.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(255, 255, 255));

                    rng.Style.Border.Top.Style = borderStyle;
                    rng.Style.Border.Top.Color.SetColor(borderColor);

                    rng.Style.Border.Bottom.Style = borderStyle;
                    rng.Style.Border.Bottom.Color.SetColor(borderColor);

                    rng.Style.Border.Right.Style = borderStyle;
                    rng.Style.Border.Right.Color.SetColor(borderColor);
                }

                //Format the header row
                using (ExcelRange rng = ws.Cells[1, 1, 1, sourceTable.Columns.Count])
                {
                    rng.Style.Font.Bold           = true;
                    rng.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                    rng.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(234, 241, 246));  //Set color to dark blue
                    rng.Style.Font.Color.SetColor(Color.FromArgb(51, 51, 51));

                    for (int i = 1; i <= rng.Columns; i++)
                    {
                        int width = CommOp.ToInt(sourceTable.Columns[i - 1].ExtendedProperties["width"]);
                        if (width > 0)
                        {
                            ws.Column(i).Width = width / 6;
                        }
                        else
                        {
                            ws.Column(i).AutoFit(20);
                        }
                    }
                    //   rng.AutoFitColumns();
                }


                MemoryStream ms = new MemoryStream(pck.GetAsByteArray());
                return(ms);
                //Write it back to the client
                //HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                //HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment;  filename={0}.xlsx", HttpUtility.UrlEncode(strFileName, Encoding.UTF8)));
                //HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;

                //HttpContext.Current.Response.BinaryWrite(pck.GetAsByteArray());
                //HttpContext.Current.Response.End();
            }
        }
Ejemplo n.º 9
0
 public static ExcelCell BorderTop(this ExcelCell @this, ExcelBorderStyle style, Color color)
 {
     @this.Cells().Style.Border.Top.Style = style;
     @this.Cells().Style.Border.Top.Color.SetColor(color);
     return(@this);
 }
Ejemplo n.º 10
0
 public static void CreateCell(ExcelWorksheet sheet, int row, int column, double value, Color?color, float size = 11, bool isFontBold = false,
                               ExcelHorizontalAlignment alignment = ExcelHorizontalAlignment.Center,
                               ExcelBorderStyle borderStyle       = ExcelBorderStyle.Medium)
 {
     CreateCell(sheet, row, column, row, column, value, color, size, isFontBold, alignment, borderStyle);
 }
Ejemplo n.º 11
0
 public static ExcelRange BordeArriba(this ExcelRange cell, ExcelBorderStyle tipoBorde = ExcelBorderStyle.Double)
 {
     cell.Style.Border.Top.Style = tipoBorde;
     return(cell);
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Tạo boder xung quanh một Cell
        /// </summary>
        /// <param name="excelWorksheet">Sheet cần tạo boder</param>
        /// <param name="rowIndex">Chỉ số hàng</param>
        /// <param name="colIndex">Chỉ số cột</param>
        /// <param name="excelBorderStyle">Kiểu đường viền</param>
        public static void FormatCellBorder(ExcelWorksheet excelWorksheet, int rowIndex, int colIndex, ExcelBorderStyle excelBorderStyle = ExcelBorderStyle.Thin)
        {
            var cell = excelWorksheet.Cells[rowIndex, colIndex];

            //căn chỉnh các border
            var border = cell.Style.Border;

            border.Bottom.Style = border.Top.Style = border.Left.Style = border.Right.Style = excelBorderStyle;
        }
Ejemplo n.º 13
0
 public static ExcelRange BordeAbajo(this ExcelRange cell, ExcelBorderStyle tipoBorde = ExcelBorderStyle.Double)
 {
     cell.Style.Border.Bottom.Style = tipoBorde;
     return(cell);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Hàm kẻ border bottom trong excel
 /// </summary>
 /// <param name="sheet"></param>
 /// <param name="startRow"></param>
 /// <param name="startColumn"></param>
 /// <param name="endStart"></param>
 /// <param name="endColumn"></param>
 /// <param name="style"></param>
 public static void RenderBorderBottom(this ExcelWorksheet sheet,
                                       int startRow, int startColumn, int endStart, int endColumn, ExcelBorderStyle style)
 {
     sheet.Cells[startRow, startColumn, endStart, endColumn].Style.Border.Bottom.Style = style;
 }
Ejemplo n.º 15
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());
            }
        }
Ejemplo n.º 16
0
        public static void AgregarTexto(this ExcelWorksheet ws, int fila, int columna, object valor, string formato, bool fontBold, ExcelBorderStyle excelBorderStyle, ExcelHorizontalAlignment horizontalAlignment)
        {
            var cell = ws.Cells[fila, columna];

            cell.Value = valor;
            cell.Style.Numberformat.Format = formato;
            cell.Style.Font.Bold           = fontBold;
            cell.Style.Border.Top.Style    = excelBorderStyle;
            cell.Style.HorizontalAlignment = horizontalAlignment;
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Set the border style around the range.
 /// </summary>
 /// <param name="Style">The border style</param>
 public void BorderAround(ExcelBorderStyle Style)
 {
     var addr = new ExcelAddress(_address);
     SetBorderAroundStyle(Style, addr);
 }
Ejemplo n.º 18
0
 public static void AllBorder(this ExcelRange range, ExcelBorderStyle borderStyle)
 {
     range.ForEach(r => r.Style.Border.BorderAround(borderStyle));
 }
Ejemplo n.º 19
0
 private void SetBorderAroundStyle(ExcelBorderStyle Style, ExcelAddress addr)
 {
     _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.BorderTop, eStyleProperty.Style, Style, _positionID, new ExcelAddress(addr._fromRow, addr._fromCol, addr._fromRow, addr._toCol).Address));
     _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.BorderBottom, eStyleProperty.Style, Style, _positionID, new ExcelAddress(addr._toRow, addr._fromCol, addr._toRow, addr._toCol).Address));
     _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.BorderLeft, eStyleProperty.Style, Style, _positionID, new ExcelAddress(addr._fromRow, addr._fromCol, addr._toRow, addr._fromCol).Address));
     _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.BorderRight, eStyleProperty.Style, Style, _positionID, new ExcelAddress(addr._fromRow, addr._toCol, addr._toRow, addr._toCol).Address));
 }
Ejemplo n.º 20
0
        /// <summary>
        /// 使用EPPlus导出Excel(xlsx)
        /// </summary>
        /// <param name="sourceTable">数据源</param>
        /// <param name="strFileName">xlsx文件名(含路径、不含后缀名)</param>
        public static string ExportExcelByEPPlus <T>(IEnumerable <T> list, string strFileName)
        {
            var sourceTable = new DataTable();

            foreach (PropertyDescriptor pd in TypeDescriptor.GetProperties(typeof(T)))
            {
                sourceTable.Columns.Add(pd.Name, pd.PropertyType);
            }
            foreach (T item in list)
            {
                var Row = sourceTable.NewRow();

                foreach (PropertyDescriptor pd in TypeDescriptor.GetProperties(typeof(T)))
                {
                    Row[pd.Name] = pd.GetValue(item);
                }
                sourceTable.Rows.Add(Row);
            }

            FileInfo file = new FileInfo(strFileName);

            if (file.Exists)
            {
                file.Delete();
                file = new FileInfo(strFileName);
            }
            using (ExcelPackage pck = new ExcelPackage(file))
            {
                //Create the worksheet
                string         sheetName = string.IsNullOrEmpty(sourceTable.TableName) ? "导出数据" : sourceTable.TableName;
                ExcelWorksheet ws        = pck.Workbook.Worksheets.Add(sheetName);

                //Load the datatable into the sheet, starting from cell A1. Print the column names on row 1
                ws.Cells["A1"].LoadFromDataTable(sourceTable, true);

                //Format the row
                ExcelBorderStyle borderStyle = ExcelBorderStyle.Thin;
                Color            borderColor = Color.FromArgb(155, 155, 155);

                using (ExcelRange rng = ws.Cells[1, 1, sourceTable.Rows.Count + 1, sourceTable.Columns.Count])
                {
                    rng.Style.Font.Name        = "宋体";
                    rng.Style.Font.Size        = 10;
                    rng.Style.Fill.PatternType = ExcelFillStyle.Solid;                      //Set Pattern for the background to Solid
                    rng.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(255, 255, 255));

                    rng.Style.Border.Top.Style = borderStyle;
                    rng.Style.Border.Top.Color.SetColor(borderColor);

                    rng.Style.Border.Bottom.Style = borderStyle;
                    rng.Style.Border.Bottom.Color.SetColor(borderColor);

                    rng.Style.Border.Right.Style = borderStyle;
                    rng.Style.Border.Right.Color.SetColor(borderColor);
                }

                //Format the header row
                using (ExcelRange rng = ws.Cells[1, 1, 1, sourceTable.Columns.Count])
                {
                    rng.Style.Font.Bold           = true;
                    rng.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                    rng.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(234, 241, 246));  //Set color to dark blue
                    rng.Style.Font.Color.SetColor(Color.FromArgb(51, 51, 51));
                }

                //Write it back to the client
                //httpContext.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                //httpContext.Response.AddHeader("content-disposition", string.Format("attachment;  filename={0}.xlsx", HttpUtility.UrlEncode(strFileName, Encoding.UTF8)));
                //httpContext.Response.ContentEncoding = Encoding.UTF8;

                //httpContext.Response.BinaryWrite(pck.GetAsByteArray());
                //httpContext.Response.End();
                pck.Save();
                return(strFileName);
            }
        }
Ejemplo n.º 21
0
 public StyleBorderBottom(ExcelBorderStyle borderStyle)
 {
     this.BorderStyle = borderStyle;
 }
Ejemplo n.º 22
0
 private static void SetStyleToAllLinesSquare(ExcelRange range, ExcelBorderStyle style)
 {
     range.Style.Border.Bottom.Style = style;
     range.Style.Border.Top.Style = style;
     range.Style.Border.Left.Style = style;
     range.Style.Border.Right.Style = style;
 }
Ejemplo n.º 23
0
 internal ExcelBorderItemXml(XmlNamespaceManager nameSpaceManager) : base(nameSpaceManager)
 {
     _borderStyle = ExcelBorderStyle.None;
     _color       = new ExcelColorXml(NameSpaceManager);
 }
Ejemplo n.º 24
0
        public void TrSetCellBorder(ExcelWorksheet xlSheet, int iRowIndex, int colIndex, ExcelBorderStyle excelBorderStyle, ExcelHorizontalAlignment excelHorizontalAlignment, Color borderColor, string fontName, int fontSize, FontStyle fontStyle)
        {
            xlSheet.Cells[iRowIndex, colIndex].Style.HorizontalAlignment = excelHorizontalAlignment;
            // Set Border
            xlSheet.Cells[iRowIndex, colIndex].Style.Border.Left.Style   = excelBorderStyle;
            xlSheet.Cells[iRowIndex, colIndex].Style.Border.Top.Style    = excelBorderStyle;
            xlSheet.Cells[iRowIndex, colIndex].Style.Border.Right.Style  = excelBorderStyle;
            xlSheet.Cells[iRowIndex, colIndex].Style.Border.Bottom.Style = excelBorderStyle;
            // Set màu ch Border
            //xlSheet.Cells[iRowIndex, colIndex].Style.Border.Left.Color.SetColor(borderColor);
            //xlSheet.Cells[iRowIndex, colIndex].Style.Border.Top.Color.SetColor(borderColor);
            //xlSheet.Cells[iRowIndex, colIndex].Style.Border.Right.Color.SetColor(borderColor);
            //xlSheet.Cells[iRowIndex, colIndex].Style.Border.Bottom.Color.SetColor(borderColor);

            // Set Font cho text  trong Range hiện tại
            xlSheet.Cells[iRowIndex, colIndex].Style.Font.SetFromFont(new System.Drawing.Font(fontName, fontSize, fontStyle));
        }
Ejemplo n.º 25
0
 public BorderProperties(IColor color, ExcelBorderStyle style, ExcelBorderPart part)
 {
     this.m_color = color;
     this.m_style = style;
     this.m_part  = part;
 }
 public ExcelHelper BorderAround(ExcelBorderStyle style)
 {
     cells.Style.Border.BorderAround(style);
     return(this);
 }
Ejemplo n.º 27
0
 private string SetBorderString(ExcelBorderStyle Style)
 {
     string newName=Enum.GetName(typeof(ExcelBorderStyle), Style);
     return newName.Substring(0, 1).ToLower() + newName.Substring(1, newName.Length - 1);
 }
Ejemplo n.º 28
0
 public static ExcelRange borderLeftRight(this ExcelRange cell, ExcelBorderStyle tipoBorde = ExcelBorderStyle.Double)
 {
     cell.Style.Border.Left.Style  = tipoBorde;
     cell.Style.Border.Right.Style = tipoBorde;
     return(cell);
 }
 public ExcelHelper BottomBorder(ExcelBorderStyle style)
 {
     cells.Style.Border.Bottom.Style = style;
     return(this);
 }
Ejemplo n.º 30
0
    public void changeformat(ExcelWorksheet ws, Font font, string data, int rownum1, int colnum1, int?rownum2 = null, int?colnum2 = null, Color?fontcolor = null, Color?bgcolor = null, bool bold = false, bool merge = true, bool italic = false, bool underline = false, ExcelVerticalAlignment vertical = ExcelVerticalAlignment.Center, ExcelHorizontalAlignment horizontal = ExcelHorizontalAlignment.Center, ExcelBorderStyle borderstyle = ExcelBorderStyle.Thin, int?txtrotate = null)
    {
        int cellAmount;
        int row2   = rownum2.HasValue ? rownum2.Value : rownum1;
        int col2   = colnum2.HasValue ? colnum2.Value : colnum1;
        int rotate = txtrotate.HasValue ? txtrotate.Value : 0;

        try
        {
            if (Int32.TryParse(data, out cellAmount))
            {
                ws.Cells[rownum1, colnum1, row2, col2].Value = cellAmount;
            }
            else
            {
                ws.Cells[rownum1, colnum1, row2, col2].Value = data;
            }
            ws.Cells[rownum1, colnum1, row2, col2].Style.TextRotation = rotate;
            ws.Cells[rownum1, colnum1, row2, col2].Merge = merge;

            ws.Cells[rownum1, colnum1, row2, col2].Style.Fill.PatternType = ExcelFillStyle.Solid;
            ws.Cells[rownum1, colnum1, row2, col2].Style.Fill.BackgroundColor.SetColor(bgcolor.HasValue?bgcolor.Value:Color.White);
            ws.Cells[rownum1, colnum1, row2, col2].Style.Font.SetFromFont(font);
            ws.Cells[rownum1, colnum1, row2, col2].Style.Font.Color.SetColor(fontcolor.HasValue?fontcolor.Value: Color.Black);
            ws.Cells[rownum1, colnum1, row2, col2].Style.Font.Bold           = bold;
            ws.Cells[rownum1, colnum1, row2, col2].Style.Font.Italic         = italic;
            ws.Cells[rownum1, colnum1, row2, col2].Style.Font.UnderLine      = underline;
            ws.Cells[rownum1, colnum1, row2, col2].Style.WrapText            = true;
            ws.Cells[rownum1, colnum1, row2, col2].Style.VerticalAlignment   = vertical;
            ws.Cells[rownum1, colnum1, row2, col2].Style.HorizontalAlignment = horizontal;
            ws.Cells[rownum1, colnum1, row2, col2].Style.Border.Left.Style   = ws.Cells[rownum1, colnum1, row2, col2].Style.Border.Bottom.Style = ws.Cells[rownum1, colnum1, row2, col2].Style.Border.Right.Style = ws.Cells[rownum1, colnum1, row2, col2].Style.Border.Top.Style = borderstyle;
        }
        catch (Exception ee)
        {
            ws.Cells[rownum1, colnum1, row2, col2].Value = ee.Message;
        }
    }
Ejemplo n.º 31
0
 /// <summary>
 /// Set the border style around the range.
 /// </summary>
 /// <param name="Style">The border style</param>
 public void BorderAround(ExcelBorderStyle Style)
 {
     BorderAround(Style, Color.Empty);
 }
Ejemplo n.º 32
0
 public static ExcelRange Border(this ExcelRange cells, Color color, ExcelBorderStyle style = ExcelBorderStyle.Thin)
 {
     cells.Style.Border.BorderAround(style, color);
     return(cells);
 }
Ejemplo n.º 33
0
        private string SetBorderString(ExcelBorderStyle Style)
        {
            string newName = Enum.GetName(typeof(ExcelBorderStyle), Style);

            return(newName.Substring(0, 1).ToLower(CultureInfo.InvariantCulture) + newName.Substring(1, newName.Length - 1));
        }
Ejemplo n.º 34
0
 internal ExcelBorderItemXml(XmlNamespaceManager nameSpaceManager)
     : base(nameSpaceManager)
 {
     _borderStyle=ExcelBorderStyle.None;
     _color = new ExcelColorXml(NameSpaceManager);
 }
Ejemplo n.º 35
0
        /// <summary>
        /// Set the border style around the range.
        /// </summary>
        /// <param name="Style">The border style</param>
        public void BorderAround(ExcelBorderStyle Style)
        {
            var addr = new ExcelAddress(_address);

            SetBorderAroundStyle(Style, addr);
        }
 public static ExcelRange SetBorder(this ExcelRange cell, ExcelBorderStyle style)
 {
     cell.Style.Border.BorderAround(style);
     return cell;
 }
Ejemplo n.º 37
0
        /// <summary>
        /// Set the border style around the range.
        /// </summary>
        /// <param name="Style">The border style</param>
        /// <param name="Color">The color of the border</param>
        public void BorderAround(ExcelBorderStyle Style, System.Drawing.Color Color)
        {            
            var addr=new ExcelAddress(_address);
            SetBorderAroundStyle(Style, addr);

            _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.BorderTop, eStyleProperty.Color, Color.ToArgb().ToString("X"), _positionID, new ExcelAddress(addr._fromRow, addr._fromCol, addr._fromRow, addr._toCol).Address));
            _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.BorderBottom, eStyleProperty.Color, Color.ToArgb().ToString("X"), _positionID, new ExcelAddress(addr._toRow, addr._fromCol, addr._toRow, addr._toCol).Address));
            _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.BorderLeft, eStyleProperty.Color, Color.ToArgb().ToString("X"), _positionID, new ExcelAddress(addr._fromRow, addr._fromCol, addr._toRow, addr._fromCol).Address));
            _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.BorderRight, eStyleProperty.Color, Color.ToArgb().ToString("X"), _positionID, new ExcelAddress(addr._fromRow, addr._toCol, addr._toRow, addr._toCol).Address));
        }
 public static ExcelRange SetBorderBottom(this ExcelRange cell, ExcelBorderStyle style)
 {
     cell.Style.Border.Bottom.Style = style;
     return cell;
 }
 /// <summary>
 ///     Sets border style around the range.
 /// </summary>
 /// <param name="thisStyle"></param>
 /// <param name="style"></param>
 /// <returns></returns>
 public static ExcelStyle BorderAround(this ExcelStyle thisStyle, ExcelBorderStyle style)
 {
     thisStyle.BorderAround(style, Color.Black);
     return(thisStyle);
 }
Ejemplo n.º 40
0
        /// <summary>
        /// Sets all borders in a given range (thanks EPPlus and Codeplex)
        /// </summary>
        /// <param name="this"></param>
        /// <param name="borderStyle"></param>
        private void SetAllBorders(ExcelRange @this, ExcelBorderStyle borderStyle)
        {
            var fromRow = @this.Start.Row;
            var fromCol = @this.Start.Column;
            var toRow = @this.End.Row;
            var toCol = @this.End.Column;

            var numRows = toRow - fromRow + 1;
            var numCols = toCol - fromCol + 1;

            @this.Style.Border.BorderAround(borderStyle);

            for (var rowOffset = 1; rowOffset < numRows; rowOffset += 2)
            {
                var row = @this.Offset(rowOffset, 0, 1, numCols);
                row.Style.Border.BorderAround(borderStyle);
            }

            for (var colOffset = 1; colOffset < numCols; colOffset += 2)
            {
                var col = @this.Offset(0, colOffset, numRows, 1);
                col.Style.Border.BorderAround(borderStyle);
            }
        }