public void Should_change_both_border_style_and_border_color_of_given_cell_range()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            ExcelRange forthColumn = excelPackage.Workbook.Worksheets.First().Cells[1, 4];

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            forthColumn.BorderAround(ExcelBorderStyle.Dashed, Color.Red);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            forthColumn.Style.Border.Left.Style.Should().Be(ExcelBorderStyle.Dashed);
            forthColumn.Style.Border.Right.Style.Should().Be(ExcelBorderStyle.Dashed);
            forthColumn.Style.Border.Top.Style.Should().Be(ExcelBorderStyle.Dashed);
            forthColumn.Style.Border.Bottom.Style.Should().Be(ExcelBorderStyle.Dashed);

            forthColumn.Style.Border.Left.Color.Rgb.Should().Be(string.Format("{0:X8}", Color.Red.ToArgb() & 0xFFFFFFFF));
            forthColumn.Style.Border.Left.Color.Rgb.Should().Be(string.Format("{0:X8}", Color.Red.ToArgb() & 0xFFFFFFFF));
            forthColumn.Style.Border.Right.Color.Rgb.Should().Be(string.Format("{0:X8}", Color.Red.ToArgb() & 0xFFFFFFFF));
            forthColumn.Style.Border.Top.Color.Rgb.Should().Be(string.Format("{0:X8}", Color.Red.ToArgb() & 0xFFFFFFFF));
            forthColumn.Style.Border.Bottom.Color.Rgb.Should().Be(string.Format("{0:X8}", Color.Red.ToArgb() & 0xFFFFFFFF));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Insert a hierarchical list in tree style into the worksheet
        /// </summary>
        /// <param name="ws">Worksheet in wich the list is inserted</param>
        /// <param name="x">Starting row of the list</param>
        /// <param name="y">Starting column of the list</param>
        /// <param name="root">Root element of the list</param>
        /// <param name="title">Title of the list</param>
        /// <param name="color">color of the list</param>
        public static void InsertHierarchicalList(this ExcelWorksheet ws, int x, int y, HierarchyElement root, string title = null, ExcelColor color = ExcelColor.Primary)
        {
            //Get hierarchy debth and the number of items in it
            int depth  = root.GetDepth();
            int length = root.GetCount();

            //Get table range
            ExcelRange range = ws.Cells[y, x, y + length - 1, x + depth - 1];


            //Format

            var palette = PaletteStorage.GetPalette(color);

            var startRow = y;


            if (title != null)
            {
                //Get the title's cells and format title
                var titleCells = ws.Cells[range.Start.Row, range.Start.Column, range.Start.Row, range.End.Column];
                titleCells.Fill(palette.MainColor);
                titleCells.Merge();
                titleCells.BorderAround();
                titleCells.Value = title;
                //if there's title then the range should be changed after (pushed down by one row)
                range = ws.Cells[range.Start.Row + 1, range.Start.Column, range.End.Row + 1, range.End.Column];
                startRow++;
            }

            //Format table under title
            range.BorderAround();
            range.Fill(palette.LightColor);

            //Insert data into formatted cells
            ws.PrintHierarchicalList(x, startRow, root);

            //Set columns to a low width
            for (int i = x; i < (x + depth - 1); i++)
            {
                ws.Column(i).Width = 2;
            }
            //set last column to autosize
            ws.Column(x + depth - 1).AutoFit();
        }
        public void Should_change_set_border_style_of_given_cell_range()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            ExcelRange forthColumn = excelPackage.Workbook.Worksheets.First().Cells[1, 4];

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            forthColumn.BorderAround(ExcelBorderStyle.Dotted);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            forthColumn.Style.Border.Left.Style.Should().Be(ExcelBorderStyle.Dotted);
            forthColumn.Style.Border.Right.Style.Should().Be(ExcelBorderStyle.Dotted);
            forthColumn.Style.Border.Top.Style.Should().Be(ExcelBorderStyle.Dotted);
            forthColumn.Style.Border.Bottom.Style.Should().Be(ExcelBorderStyle.Dotted);
        }