Is there a way to simply apply a style to a bunch of cells ?

Posted by: lotfi on 10 September 2017, 10:58 am EST

  • Posted 10 September 2017, 10:58 am EST

    Hello Everyone,

     

    I'm looking for a way to apply a style output ( background and text color, Font name and name, etc.) to a specified row or a column, but not to whole row, or column, just part of them.

    I use to apply this in Excel by simply selecting a range of cells, and apply to it the style output.

     

    Thank you in advance guys.

    Lotfi B. 

  • Replied 10 September 2017, 10:58 am EST

    Hello,

    Here is the code to apply style to a range of cells:

     
      private void button1_Click(object sender, RoutedEventArgs e)

            {

                Worksheet sheet = this.gcSpreadSheet1.ActiveSheet;

                foreach (CellRange cellRange in sheet.Selections)

                {

                    CellRange range = GetActualCellRange(cellRange, sheet.RowCount, sheet.ColumnCount);

                    for (int i = 0; i < range.RowCount; i++)

                    {

                        for (int j = 0; j < range.ColumnCount; j++)

                        {

                            sheet.Cells[range.Row + i, range.Column + j].Background = new SolidColorBrush(Colors.Blue);

      

                        }

                    }

                }

     
            }

            private CellRange GetActualCellRange(CellRange cellRange, int rowCount, int columnCount)

            {

                if (cellRange.Row == -1 && cellRange.Column == -1)

                {

                    return new CellRange(0, 0, rowCount, columnCount);

                }

                else if (cellRange.Row == -1)

                {

                    return new CellRange(0, cellRange.Column, rowCount, cellRange.ColumnCount);

                }

                else if (cellRange.Column == -1)

                {

                    return new CellRange(cellRange.Row, 0, cellRange.RowCount, columnCount);

                }

     
                return cellRange;

            }

     

    Thanks,

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels