﻿Imports FarPoint.Win.Spread
Imports GrapeCity.Spreadsheet
Imports Spread.Common.Features.Spread.Common.Features.Sample
Imports System


Partial Public Class CenterAcrossSelection
    Inherits BaseSampleControl
    Public Sub New()
        InitializeComponent()
        Name = "Center Across Selection"
        SetupSheet(_fpSpread)
    End Sub

    Private Sub SetupSheet(ByVal spread As FpSpread)
        Dim workbook As IWorkbook = spread.AsWorkbook()
        spread.Features.ExcelCompatibleKeyboardShortcuts = True

        ' Enable center across selection
        spread.AllowCellOverflow = True
        spread.BorderCollapse = BorderCollapse.Enhanced

        Dim cas As IStyle = workbook.Styles.Add("cas")
        cas.HorizontalAlignment = HorizontalAlignment.CenterAcrossSelection

        Dim borderStyle As BorderLineStyle = BorderLineStyle.Thin
        Dim borderColor As Color = Color.FromKnownColor(GrapeCity.Core.KnownColor.Black)
        Dim border As Border = New Border(New BorderLine(borderStyle, borderColor))
        cas.Borders.ApplyBorder(border)

        Dim workSheet As IWorksheet = workbook.ActiveSheet
        workSheet.Name = "Center Across Selection"

        Dim column As Integer = 1
        For Each Weekday As String In [Enum].GetNames(GetType(DayOfWeek))
            workSheet.Cells(1, column).Value = Weekday
            workSheet.Columns(column).ColumnWidth = 150
            column += 1
        Next

        For Hour As Integer = 12 To 16
            Dim cell As String = $"A{Hour - 9}"
            workSheet.Cells(cell).Value = $"{Hour}:00"
        Next

        workSheet.Columns("A").ColumnWidth = 100

        workSheet.Cells("A2:H7").Borders.ApplyBorder(border)
        workSheet.Cells("B3").Value = "Walker"
        workSheet.Cells("B4:B5").Value = "Today News"
        workSheet.Cells("B6:B7").Value = "News"
        workSheet.Cells("C3").Value = "Morning Show"
        workSheet.Cells("D4").Value = "Sesame Street"
        workSheet.Cells("D5").Value = "Kids Zone"
        workSheet.Cells("E3").Value = "Sport"
        workSheet.Cells("E4:E5").Value = "Football"
        workSheet.Cells("F3").Value = "Weather"
        workSheet.Cells("F4").Value = "Market Watch"
        workSheet.Cells("F4").Value = "Soap Opera"
        workSheet.Cells("G3:G7").Value = "N/A"
        workSheet.Cells("A2:H7").Select()
    End Sub

    Private Sub OnCenterAcrossSelectionClick(ByVal sender As Object, ByVal e As EventArgs)
        Dim workbook As IWorksheet = _fpSpread.AsWorkbook().ActiveSheet
        Dim selection As IRange = workbook.Selection
        workbook.Cells(selection.Row, selection.Column, selection.Row2, selection.Column2).ApplyStyle("cas")
    End Sub
End Class
