Imports FarPoint.Win
Imports FarPoint.Win.Spread
Imports FarPoint.Win.Spread.CellType
Imports FarPoint.Win.Spread.Model
Imports GrapeCity.Spreadsheet
Imports Spread.Common.Features.Spread.Common.Features.Sample
Imports System.Collections
Imports System.Collections.Generic
Imports System.Windows.Forms

Namespace Features
    Partial Public Class CellStyles
        Inherits BaseSampleControl
        Private newStyle As NewStyle = Nothing
        Private customStyles As New List(Of String)()
        Public Sub New()
            InitializeComponent()
            AddHandler Me.Load, AddressOf Form1_Load
        End Sub

        Private Sub Form1_Load(sender As Object, e As EventArgs)
            fpSpread2.ActiveSheet = fpSpread2_Sheet1
            Dim wb As Workbook = DirectCast(fpSpread2.AsWorkbook(), Workbook)
            Dim ws As GrapeCity.Spreadsheet.Worksheet = DirectCast(wb.ActiveSheet, GrapeCity.Spreadsheet.Worksheet)
            fpSpread2_Sheet1.RowCount = 50
            ' set styles
            ws.Cells(1, 0).ApplyStyle(BuiltInStyle.Normal)
            ws.Cells(1, 1).ApplyStyle(BuiltInStyle.Bad)
            ws.Cells(1, 2).ApplyStyle(BuiltInStyle.Good)
            ws.Cells(1, 3).ApplyStyle(BuiltInStyle.Neutral)
            ws.Cells(3, 0).ApplyStyle(BuiltInStyle.Calculation)
            ws.Cells(3, 1).ApplyStyle(BuiltInStyle.CheckCell)
            ws.Cells(3, 2).ApplyStyle(BuiltInStyle.ExplanatoryText)
            ws.Cells(3, 3).ApplyStyle(BuiltInStyle.Input)
            ws.Cells(3, 4).ApplyStyle(BuiltInStyle.LinkedCell)
            ws.Cells(3, 5).ApplyStyle(BuiltInStyle.Note)
            ws.Cells(4, 0).ApplyStyle(BuiltInStyle.Output)
            ws.Cells(4, 1).ApplyStyle(BuiltInStyle.WarningText)
            ws.Cells(6, 0).ApplyStyle(BuiltInStyle.Heading1)
            ws.Cells(6, 1).ApplyStyle(BuiltInStyle.Heading2)
            ws.Cells(6, 2).ApplyStyle(BuiltInStyle.Heading3)
            ws.Cells(6, 3).ApplyStyle(BuiltInStyle.Heading4)
            ws.Cells(6, 4).ApplyStyle(BuiltInStyle.Title)
            ws.Cells(6, 5).ApplyStyle(BuiltInStyle.Total)
            ws.Cells(8, 0).ApplyStyle(BuiltInStyle.Percent20Accent1)
            ws.Cells(8, 1).ApplyStyle(BuiltInStyle.Percent20Accent2)
            ws.Cells(8, 2).ApplyStyle(BuiltInStyle.Percent20Accent3)
            ws.Cells(8, 3).ApplyStyle(BuiltInStyle.Percent20Accent4)
            ws.Cells(8, 4).ApplyStyle(BuiltInStyle.Percent20Accent5)
            ws.Cells(8, 5).ApplyStyle(BuiltInStyle.Percent20Accent6)
            ws.Cells(9, 0).ApplyStyle(BuiltInStyle.Percent40Accent1)
            ws.Cells(9, 1).ApplyStyle(BuiltInStyle.Percent40Accent2)
            ws.Cells(9, 2).ApplyStyle(BuiltInStyle.Percent40Accent3)
            ws.Cells(9, 3).ApplyStyle(BuiltInStyle.Percent40Accent4)
            ws.Cells(9, 4).ApplyStyle(BuiltInStyle.Percent40Accent5)
            ws.Cells(9, 5).ApplyStyle(BuiltInStyle.Percent40Accent6)
            ws.Cells(10, 0).ApplyStyle(BuiltInStyle.Percent60Accent1)
            ws.Cells(10, 1).ApplyStyle(BuiltInStyle.Percent60Accent2)
            ws.Cells(10, 2).ApplyStyle(BuiltInStyle.Percent60Accent3)
            ws.Cells(10, 3).ApplyStyle(BuiltInStyle.Percent60Accent4)
            ws.Cells(10, 4).ApplyStyle(BuiltInStyle.Percent60Accent5)
            ws.Cells(10, 5).ApplyStyle(BuiltInStyle.Percent60Accent6)
            ws.Cells(11, 0).ApplyStyle(BuiltInStyle.Accent1)
            ws.Cells(11, 1).ApplyStyle(BuiltInStyle.Accent2)
            ws.Cells(11, 2).ApplyStyle(BuiltInStyle.Accent3)
            ws.Cells(11, 3).ApplyStyle(BuiltInStyle.Accent4)
            ws.Cells(11, 4).ApplyStyle(BuiltInStyle.Accent5)
            ws.Cells(11, 5).ApplyStyle(BuiltInStyle.Accent6)
            ws.Cells(13, 0).ApplyStyle(BuiltInStyle.Comma)
            ws.Cells(13, 1).ApplyStyle(BuiltInStyle.Comma0)
            ws.Cells(13, 2).ApplyStyle(BuiltInStyle.Currency)
            ws.Cells(13, 3).ApplyStyle(BuiltInStyle.Currency0)
            ws.Cells(13, 4).ApplyStyle(BuiltInStyle.Percent)
            fpSpread2_Sheet1.Cells(0, 0).BackColor = System.Drawing.Color.FromArgb(255, 74, 74, 74)
            fpSpread2_Sheet1.Cells(2, 0).BackColor = System.Drawing.Color.FromArgb(255, 74, 74, 74)
            fpSpread2_Sheet1.Cells(5, 0).BackColor = System.Drawing.Color.FromArgb(255, 74, 74, 74)
            fpSpread2_Sheet1.Cells(7, 0).BackColor = System.Drawing.Color.FromArgb(255, 74, 74, 74)
            fpSpread2_Sheet1.Cells(12, 0).BackColor = System.Drawing.Color.FromArgb(255, 74, 74, 74)
            fpSpread2_Sheet1.Cells(14, 0).BackColor = System.Drawing.Color.FromArgb(255, 74, 74, 74)
            fpSpread2_Sheet1.Cells(0, 0).ForeColor = System.Drawing.Color.FromArgb(255, 235, 235, 235)
            fpSpread2_Sheet1.Cells(2, 0).ForeColor = System.Drawing.Color.FromArgb(255, 235, 235, 235)
            fpSpread2_Sheet1.Cells(5, 0).ForeColor = System.Drawing.Color.FromArgb(255, 235, 235, 235)
            fpSpread2_Sheet1.Cells(7, 0).ForeColor = System.Drawing.Color.FromArgb(255, 235, 235, 235)
            fpSpread2_Sheet1.Cells(12, 0).ForeColor = System.Drawing.Color.FromArgb(255, 235, 235, 235)
            fpSpread2_Sheet1.Cells(14, 0).ForeColor = System.Drawing.Color.FromArgb(255, 235, 235, 235)
            fpSpread2_Sheet1.Cells(0, 0).CanFocus = False
            fpSpread2_Sheet1.Cells(1, 4, 1, 5).CanFocus = False
            fpSpread2_Sheet1.Cells(1, 4, 1, 5).BackColor = System.Drawing.Color.Black
            fpSpread2_Sheet1.Cells(2, 0).CanFocus = False
            fpSpread2_Sheet1.Cells(4, 2, 4, 5).CanFocus = False
            fpSpread2_Sheet1.Cells(4, 2, 4, 5).BackColor = System.Drawing.Color.Black
            fpSpread2_Sheet1.Cells(5, 0).CanFocus = False
            fpSpread2_Sheet1.Cells(7, 0).CanFocus = False
            fpSpread2_Sheet1.Cells(12, 0).CanFocus = False
            fpSpread2_Sheet1.Cells(13, 5).CanFocus = False
            fpSpread2_Sheet1.Cells(14, 5).CanFocus = False
            fpSpread2_Sheet1.Cells(13, 5).BackColor = System.Drawing.Color.Black
            fpSpread2_Sheet1.Cells(15, 0, 46, 5).BackColor = System.Drawing.Color.Black
            Dim border As New Border(New BorderLine(BorderLineStyle.Thick, GrapeCity.Spreadsheet.Color.FromKnownColor(GrapeCity.Core.KnownColor.Black)))
            ws.Cells(1, 0, 1, 3).Borders.ApplyBorder(border)
            ws.Cells(3, 0, 3, 5).Borders.ApplyBorder(border)
            ws.Cells(4, 0, 4, 1).Borders.ApplyBorder(border)
            ws.Cells(6, 0, 6, 5).Borders.ApplyBorder(border)
            ws.Cells(8, 0, 11, 5).Borders.ApplyBorder(border)
            ws.Cells(13, 0, 13, 5).Borders.ApplyBorder(border)
            ws.Cells(15, 0, 46, 5).Borders.ApplyBorder(border)
            Dim gl As New GridLine(GridLineType.None)
            fpSpread2_Sheet1.HorizontalGridLine = gl
            fpSpread2_Sheet1.VerticalGridLine = gl
            fpSpread2_Sheet1.Cells(14, 0).ColumnSpan = 6
            fpSpread2_Sheet1.Cells(14, 0).CellPadding.All = 0
            fpSpread2_Sheet1.Cells(14, 0).Text = "Custom Styles"
            fpSpread2_Sheet1.Rows(15, 46).Height = 0
            fpSpread2_Sheet1.Cells(48, 0).ColumnSpan = 6
            fpSpread2_Sheet1.Cells(48, 0).CellPadding.All = 0
            Dim newStyle As New TextCellType()
            newStyle.BackgroundImage = New Picture(My.Resources.new_style)
            newStyle.BackgroundImage.AlignHorz = FarPoint.Win.HorizontalAlignment.Left
            newStyle.BackgroundImage.AlignVert = FarPoint.Win.VerticalAlignment.Center
            newStyle.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show
            fpSpread2_Sheet1.Cells(48, 0).BackColor = System.Drawing.Color.Black
            fpSpread2_Sheet1.Cells(48, 0).CellType = newStyle
            fpSpread2_Sheet1.Cells(48, 0).ForeColor = System.Drawing.Color.FromArgb(255, 240, 240, 240)
            fpSpread2_Sheet1.Cells(48, 0).HorizontalAlignment = CellHorizontalAlignment.Left
            fpSpread2_Sheet1.Cells(48, 0).Text = "&New Cell Style..."
            fpSpread2_Sheet1.Cells(48, 0).TextIndent = 26
            fpSpread2_Sheet1.Rows(47).Height = 2
            fpSpread2_Sheet1.Rows(49).Height = 0
            fpSpread2_Sheet1.Cells(47, 0, 47, 5).Border = New ComplexBorder(ComplexBorderSide.Empty, New ComplexBorderSide(ComplexBorderSideStyle.ThinLine, System.Drawing.Color.FromArgb(255, 74, 74, 74)), ComplexBorderSide.Empty, ComplexBorderSide.Empty)
            fpSpread2_Sheet1.Rows(48).Height = 26
            fpSpread2_Sheet1.FrozenTrailingRowCount = 4
            fpSpread2_Sheet1.GrayAreaBackColor = System.Drawing.Color.Black
            fpSpread2.SetCursor(CursorType.Normal, Cursors.Arrow)
            fpSpread2_Sheet1.SetActiveCell(1, 0)
        End Sub

        Private Sub fpSpread2_CellClick(sender As Object, e As FarPoint.Win.Spread.CellClickEventArgs)
            If e.Row = 0 OrElse e.Row = 2 OrElse e.Row = 5 OrElse e.Row = 7 OrElse e.Row = 12 Then
                Return
            End If
            If e.Row = 1 AndAlso e.Column > 3 Then
                Return
            End If
            If e.Row = 5 AndAlso e.Column > 1 Then
                Return
            End If
            If e.Row = 13 AndAlso e.Column > 4 Then
                Return
            End If
            If e.Row = 48 AndAlso e.Column = 0 Then
                If customStyles.Count > 50 Then
                    MessageBox.Show("You cannot create more then 50 style here.")
                    Return
                End If
                newStyle = New NewStyle()
                AddHandler newStyle.OpenFormatDialog, AddressOf NewStyle_OpenFormatDialog
                AddHandler newStyle.OKdialog, AddressOf NewStyle_OKdialog
                newStyle.ShowDialog()
                Return
            End If

            Dim wb As Workbook = DirectCast(fpSpread1.AsWorkbook(), Workbook)
            Dim ws As GrapeCity.Spreadsheet.Worksheet = DirectCast(wb.ActiveSheet, GrapeCity.Spreadsheet.Worksheet)
            Dim selections As CellRange() = fpSpread1.ActiveSheet.GetSelections()
            If selections.Length = 0 Then
                selections = New CellRange() {New CellRange(fpSpread1.ActiveSheet.ActiveRowIndex, fpSpread1.ActiveSheet.ActiveColumnIndex, 1, 1)}
            End If
            For Each cr As CellRange In selections
                If cr.Row = -1 Then
                    If cr.Column = -1 Then
                        ws.Cells.Style = fpSpread2.AsWorkbook().ActiveSheet.Cells(e.Row, e.Column).Style
                        fpSpread1.ActiveSheet.DefaultStyle.CellType = fpSpread2.ActiveSheet.Cells(e.Row, e.Column).CellType
                    Else
                        ws.Columns(cr.Column, cr.Column + cr.ColumnCount - 1).Style = fpSpread2.AsWorkbook().ActiveSheet.Cells(e.Row, e.Column).Style
                        fpSpread1.ActiveSheet.Columns(cr.Column, cr.Column + cr.ColumnCount - 1).CellType = fpSpread2.ActiveSheet.Cells(e.Row, e.Column).CellType
                    End If
                ElseIf cr.Column = -1 Then
                    ws.Rows(cr.Row, cr.Row + cr.RowCount - 1).Style = fpSpread2.AsWorkbook().ActiveSheet.Cells(e.Row, e.Column).Style
                    fpSpread1.ActiveSheet.Rows(cr.Row, cr.Row + cr.RowCount - 1).CellType = fpSpread2.ActiveSheet.Cells(e.Row, e.Column).CellType
                Else
                    ws.Cells(cr.Row, cr.Column, cr.Row + cr.RowCount - 1, cr.Column + cr.ColumnCount - 1).Style = fpSpread2.AsWorkbook().ActiveSheet.Cells(e.Row, e.Column).Style
                    fpSpread1.ActiveSheet.Cells(cr.Row, cr.Column, cr.Row + cr.RowCount - 1, cr.Column + cr.ColumnCount - 1).CellType = fpSpread2.ActiveSheet.Cells(e.Row, e.Column).CellType
                End If
            Next
            Text = "Applied style """ & fpSpread2.AsWorkbook().ActiveSheet.Cells(e.Row, e.Column).Style.Name & """"
        End Sub

        Private Sub NewStyle_OKdialog(s As Object, e As EventArgs)
            If String.IsNullOrEmpty(newStyle.StyleName) Then
                MessageBox.Show("Please enter a style name first.")
                Return
            End If
            Dim styleFormat = DirectCast(DirectCast(fpSpread2.AsWorkbook(), Workbook).ActiveSheet, GrapeCity.Spreadsheet.Worksheet).GetStyleFormat(49, 0)
            Dim celltype = fpSpread2.ActiveSheet.Cells(49, 0).CellType
            For row As Integer = 15 To 46
                For col As Integer = 0 To 5
                    Dim stylePresent = fpSpread2.AsWorkbook().Styles(fpSpread2.AsWorkbook().ActiveSheet.Cells(row, col).Style.Name)
                    If stylePresent.Name = "Normal" Then
                        Dim style As IStyle = ConvertStyleFormatToIStyle(newStyle.StyleName, styleFormat, newStyle.IncludeBorder, newStyle.IncludeAlignment, newStyle.IncludeProtection, newStyle.IncludePatterns,
                            newStyle.IncludeNumber, newStyle.IncludeFont)
                        If style Is Nothing Then
                            Return
                        End If

                        DirectCast(DirectCast(fpSpread2.AsWorkbook(), Workbook).ActiveSheet, GrapeCity.Spreadsheet.Worksheet).Cells(row, col).Style = style
                        fpSpread2.ActiveSheet.Cells(row, col).CellType = celltype
                        fpSpread2.ActiveSheet.Cells(row, col).Text = style.Name
                        customStyles.Add(style.Name)
                        If newStyle.IncludeBorder Then
                            DirectCast(DirectCast(fpSpread2.AsWorkbook(), Workbook).ActiveSheet, GrapeCity.Spreadsheet.Worksheet).Cells(row, col).Borders.ApplyBorder(styleFormat.Border)
                        End If

                        fpSpread2.ActiveSheet.Rows(row).Height = fpSpread2.ActiveSheet.Rows(row).GetPreferredHeight()
                        newStyle.Dispose()
                        fpSpread2.ActiveSheet.Cells(49, 0).ResetCellType()
                        DirectCast(DirectCast(fpSpread2.AsWorkbook(), Workbook).ActiveSheet, GrapeCity.Spreadsheet.Worksheet).Cells(49, 0).ApplyStyle("Normal")
                        Return
                    End If
                Next
            Next
        End Sub

        Private Sub NewStyle_OpenFormatDialog(s As Object, e As EventArgs)
            Dim wb As Workbook = DirectCast(fpSpread2.AsWorkbook(), Workbook)
            Dim workbook As Workbook = wb
            Dim ws As GrapeCity.Spreadsheet.Worksheet = DirectCast(wb.ActiveSheet, GrapeCity.Spreadsheet.Worksheet)
            Dim selections As CellRange() = New CellRange() {New CellRange(49, 0, 1, 1)}
            Dim sels As New ArrayList()
            For Each cr As CellRange In selections
                sels.Add(ws.Cells(cr.Row, cr.Column, cr.Row + cr.RowCount - 1, cr.Column + cr.ColumnCount - 1))
            Next
            Dim sels_ As IRange() = New IRange(sels.Count - 1) {}
            sels.CopyTo(sels_)
            Dim dlg As New FormatCells(sels_(0))
            dlg.ShowDialog(Me)
        End Sub

        Private Enum ft
            theme
            color
            effect
            font
        End Enum
        Private Function GetThemeToApply(initDir As ft, filter As String) As String
            Dim filename As String = Nothing
            Dim ofd As New OpenFileDialog()
            ofd.Filter = filter
            ofd.FilterIndex = 0
            Select Case initDir
                Case ft.theme
                    If System.IO.Directory.Exists("C:\Program Files (x86)\Microsoft Office\root\Document Themes 16") Then
                        ofd.InitialDirectory = "C:\Program Files (x86)\Microsoft Office\root\Document Themes 16"
                    End If
                    Exit Select
                Case ft.color
                    If System.IO.Directory.Exists("C:\Program Files (x86)\Microsoft Office\root\Document Themes 16\Theme Colors") Then
                        ofd.InitialDirectory = "C:\Program Files (x86)\Microsoft Office\root\Document Themes 16\Theme Colors"
                    End If
                    Exit Select
                Case ft.effect
                    If System.IO.Directory.Exists("C:\Program Files (x86)\Microsoft Office\root\Document Themes 16\Theme Effects") Then
                        ofd.InitialDirectory = "C:\Program Files (x86)\Microsoft Office\root\Document Themes 16\Theme Effects"
                    End If
                    Exit Select
                Case ft.font
                    If System.IO.Directory.Exists("C:\Program Files (x86)\Microsoft Office\root\Document Themes 16\Theme Fonts") Then
                        ofd.InitialDirectory = "C:\Program Files (x86)\Microsoft Office\root\Document Themes 16\Theme Fonts"
                    End If
                    Exit Select
            End Select
            ofd.Title = "Apply Theme From File"
            If ofd.ShowDialog(Me) = DialogResult.OK Then
                filename = ofd.FileName
            End If
            Return filename
        End Function

        Private Sub themeApplyThemeToolStripMenuItem_Clicked(sender As Object, e As EventArgs)
            Dim fileName As String = GetThemeToApply(ft.theme, "Excel Theme (*.THMX;*.XLSX)|*.THMX;*.XLSX|All Files (*.*)|*.*")
            If fileName IsNot Nothing Then
                Try
                    fpSpread1.AsWorkbook().ApplyTheme(fileName)
                    fpSpread2.AsWorkbook().ApplyTheme(fpSpread1.AsWorkbook().Theme)
                Catch ex As Exception
                    Dim dlg As New ThreadExceptionDialog(ex)
                    dlg.ShowDialog(Me)
                End Try
            End If
        End Sub

        Private Sub themeApplyColorSchemeToolStripMenuItem_Clicked(sender As Object, e As EventArgs)
            Dim fileName As String = GetThemeToApply(ft.color, "Excel Theme Colors (*.XML)|*.XML|All Files (*.*)|*.*")
            If fileName IsNot Nothing Then
                Try
                    fpSpread1.AsWorkbook().Theme.ColorScheme.Load(fileName)
                    fpSpread2.AsWorkbook().Theme.ColorScheme.Load(fileName)
                Catch ex As Exception
                    Dim dlg As New ThreadExceptionDialog(ex)
                    dlg.ShowDialog(Me)
                End Try
            End If
        End Sub

        Private Sub themeApplyEffectsSchemeToolStripMenuItem_Clicked(sender As Object, e As EventArgs)
            Dim fileName As String = GetThemeToApply(ft.effect, "Excel Theme Effects (*.EFTX)|*.EFTX|All Files (*.*)|*.*")
            If fileName IsNot Nothing Then
                Try
                    fpSpread1.AsWorkbook().Theme.EffectScheme.Load(fileName)
                    fpSpread2.AsWorkbook().Theme.EffectScheme.Load(fileName)
                Catch ex As Exception
                    Dim dlg As New ThreadExceptionDialog(ex)
                    dlg.ShowDialog(Me)
                End Try
            End If
        End Sub

        Private Sub themeApplyFontSchemeToolStripMenuItem_Clicked(sender As Object, e As EventArgs)
            Dim fileName As String = GetThemeToApply(ft.font, "Excel Theme Font (*.XML)|*.XML|All Files (*.*)|*.*")
            If fileName IsNot Nothing Then
                Try
                    fpSpread1.AsWorkbook().Theme.FontScheme.Load(fileName)
                    fpSpread2.AsWorkbook().Theme.FontScheme.Load(fileName)
                Catch ex As Exception
                    Dim dlg As New ThreadExceptionDialog(ex)
                    dlg.ShowDialog(Me)
                End Try
            End If
        End Sub

        Private Sub formatCellsToolStripMenuItem_Click(sender As Object, e As EventArgs)
            Dim wb As Workbook = DirectCast(fpSpread1.AsWorkbook(), Workbook)
            Dim workbook As Workbook = wb
            Dim ws As GrapeCity.Spreadsheet.Worksheet = DirectCast(wb.ActiveSheet, GrapeCity.Spreadsheet.Worksheet)
            Dim selections As CellRange() = fpSpread1.ActiveSheet.GetSelections()
            If selections.Length = 0 Then
                selections = New CellRange() {New CellRange(fpSpread1.ActiveSheet.ActiveRowIndex, fpSpread1.ActiveSheet.ActiveColumnIndex, 1, 1)}
            End If
            Dim sels As New ArrayList()
            For Each cr As CellRange In selections
                sels.Add(ws.Cells(cr.Row, cr.Column, cr.Row + cr.RowCount - 1, cr.Column + cr.ColumnCount - 1))
            Next
            Dim sels_ As IRange() = New IRange(sels.Count - 1) {}
            sels.CopyTo(sels_)
            Dim dlg As New FormatCells(sels_(0))
            dlg.ShowDialog(Me)
        End Sub

    Private Sub ApplyStyleAndCellTypeOnRange(style As IStyle, cellType As CellType.ICellType, worksheet As IWorksheet, sheetView As SheetView, startRow As Integer, startCol As Integer,
            lastRow As Integer, lastCol As Integer)
      worksheet.Cells(startRow, startCol, lastRow, lastCol).Style = style
      sheetView.Cells(startRow, startCol, lastRow, lastCol).CellType = cellType
    End Sub
    Private Function ConvertStyleFormatToIStyle(stylename As String, styleFormat As StyleFormat, includeBorder As Boolean, includeAlignment As Boolean, includeProtection As Boolean, includePatterns As Boolean,
            includeNumber As Boolean, includeFont As Boolean) As IStyle
            Dim duplicatedGoodStyle = fpSpread2.AsWorkbook().Styles(stylename)
            If duplicatedGoodStyle Is Nothing Then
                duplicatedGoodStyle = fpSpread2.AsWorkbook().Styles.Add(stylename, "Good")
            Else
                MessageBox.Show("This style name is already exist. Please enter a new name.")
                Return Nothing
            End If
            duplicatedGoodStyle.IncludeBorder = includeBorder
            duplicatedGoodStyle.IncludeAlignment = includeAlignment
            duplicatedGoodStyle.IncludeProtection = includeProtection
            duplicatedGoodStyle.IncludePatterns = includePatterns
            duplicatedGoodStyle.IncludeNumber = includeNumber
            duplicatedGoodStyle.IncludeFont = includeFont
            duplicatedGoodStyle.Font.ApplyFont(styleFormat.Font)
            duplicatedGoodStyle.IndentLevel = styleFormat.Alignment.Indent
            duplicatedGoodStyle.HorizontalAlignment = styleFormat.Alignment.HAlignment
            duplicatedGoodStyle.VerticalAlignment = styleFormat.Alignment.VAlignment
            duplicatedGoodStyle.ShrinkToFit = styleFormat.Alignment.ShrinkToFit
            duplicatedGoodStyle.WrapText = styleFormat.Alignment.WrapText
            duplicatedGoodStyle.Orientation = styleFormat.Alignment.TextRotation
            duplicatedGoodStyle.Locked = styleFormat.Protection.Locked
            duplicatedGoodStyle.NumberFormat = styleFormat.NumberFormat
            duplicatedGoodStyle.Borders.ApplyBorder(styleFormat.Border)
            duplicatedGoodStyle.Interior.ApplyInterior(styleFormat.Fill)
            Return duplicatedGoodStyle
        End Function


        Private Sub fpSpread1_LeaveCell(sender As Object, e As LeaveCellEventArgs)
            Dim wb As Workbook = DirectCast(fpSpread1.AsWorkbook(), Workbook)
            Dim ws As GrapeCity.Spreadsheet.Worksheet = DirectCast(wb.ActiveSheet, GrapeCity.Spreadsheet.Worksheet)
            Dim sv As SheetView = fpSpread1.ActiveSheet
            Dim s As IStyle = ws.Cells(e.NewRow, e.NewColumn).Style
            If s.BuiltIn Then
                Select Case s.Name
                    Case "Normal"
                        fpSpread2_Sheet1.SetActiveCell(1, 0)
                        Exit Select
                    Case "Bad"
                        fpSpread2_Sheet1.SetActiveCell(1, 1)
                        Exit Select
                    Case "Good"
                        fpSpread2_Sheet1.SetActiveCell(1, 2)
                        Exit Select
                    Case "Neutral"
                        fpSpread2_Sheet1.SetActiveCell(1, 3)
                        Exit Select
                    Case "Calculation"
                        fpSpread2_Sheet1.SetActiveCell(3, 0)
                        Exit Select
                    Case "Check Cell"
                        fpSpread2_Sheet1.SetActiveCell(3, 1)
                        Exit Select
                    Case "Explanatory Text"
                        fpSpread2_Sheet1.SetActiveCell(3, 2)
                        Exit Select
                    Case "Input"
                        fpSpread2_Sheet1.SetActiveCell(3, 3)
                        Exit Select
                    Case "Linked Cell"
                        fpSpread2_Sheet1.SetActiveCell(3, 4)
                        Exit Select
                    Case "Note"
                        fpSpread2_Sheet1.SetActiveCell(3, 5)
                        Exit Select
                    Case "Output"
                        fpSpread2_Sheet1.SetActiveCell(4, 0)
                        Exit Select
                    Case "Warning Text"
                        fpSpread2_Sheet1.SetActiveCell(4, 1)
                        Exit Select
                    Case "Heading1"
                        fpSpread2_Sheet1.SetActiveCell(6, 0)
                        Exit Select
                    Case "Heading2"
                        fpSpread2_Sheet1.SetActiveCell(6, 1)
                        Exit Select
                    Case "Heading3"
                        fpSpread2_Sheet1.SetActiveCell(6, 2)
                        Exit Select
                    Case "Heading4"
                        fpSpread2_Sheet1.SetActiveCell(6, 3)
                        Exit Select
                    Case "Title"
                        fpSpread2_Sheet1.SetActiveCell(6, 4)
                        Exit Select
                    Case "Total"
                        fpSpread2_Sheet1.SetActiveCell(6, 5)
                        Exit Select
                    Case "20% - Accent1"
                        fpSpread2_Sheet1.SetActiveCell(8, 0)
                        Exit Select
                    Case "20% - Accent2"
                        fpSpread2_Sheet1.SetActiveCell(8, 1)
                        Exit Select
                    Case "20% - Accent3"
                        fpSpread2_Sheet1.SetActiveCell(8, 2)
                        Exit Select
                    Case "20% - Accent4"
                        fpSpread2_Sheet1.SetActiveCell(8, 3)
                        Exit Select
                    Case "20% - Accent5"
                        fpSpread2_Sheet1.SetActiveCell(8, 4)
                        Exit Select
                    Case "20% - Accent6"
                        fpSpread2_Sheet1.SetActiveCell(8, 5)
                        Exit Select
                    Case "40% - Accent1"
                        fpSpread2_Sheet1.SetActiveCell(9, 0)
                        Exit Select
                    Case "40% - Accent2"
                        fpSpread2_Sheet1.SetActiveCell(9, 1)
                        Exit Select
                    Case "40% - Accent3"
                        fpSpread2_Sheet1.SetActiveCell(9, 2)
                        Exit Select
                    Case "40% - Accent4"
                        fpSpread2_Sheet1.SetActiveCell(9, 3)
                        Exit Select
                    Case "40% - Accent5"
                        fpSpread2_Sheet1.SetActiveCell(9, 4)
                        Exit Select
                    Case "40% - Accent6"
                        fpSpread2_Sheet1.SetActiveCell(9, 5)
                        Exit Select
                    Case "60% - Accent1"
                        fpSpread2_Sheet1.SetActiveCell(10, 0)
                        Exit Select
                    Case "60% - Accent2"
                        fpSpread2_Sheet1.SetActiveCell(10, 1)
                        Exit Select
                    Case "60% - Accent3"
                        fpSpread2_Sheet1.SetActiveCell(10, 2)
                        Exit Select
                    Case "60% - Accent4"
                        fpSpread2_Sheet1.SetActiveCell(10, 3)
                        Exit Select
                    Case "60% - Accent5"
                        fpSpread2_Sheet1.SetActiveCell(10, 4)
                        Exit Select
                    Case "60% - Accent6"
                        fpSpread2_Sheet1.SetActiveCell(10, 5)
                        Exit Select
                    Case "Accent1"
                        fpSpread2_Sheet1.SetActiveCell(11, 0)
                        Exit Select
                    Case "Accent2"
                        fpSpread2_Sheet1.SetActiveCell(11, 1)
                        Exit Select
                    Case "Accent3"
                        fpSpread2_Sheet1.SetActiveCell(11, 2)
                        Exit Select
                    Case "Accent4"
                        fpSpread2_Sheet1.SetActiveCell(11, 3)
                        Exit Select
                    Case "Accent5"
                        fpSpread2_Sheet1.SetActiveCell(11, 4)
                        Exit Select
                    Case "Accent6"
                        fpSpread2_Sheet1.SetActiveCell(11, 5)
                        Exit Select
                    Case "Comma"
                        fpSpread2_Sheet1.SetActiveCell(13, 0)
                        Exit Select
                    Case "Comma [0]"
                        fpSpread2_Sheet1.SetActiveCell(13, 1)
                        Exit Select
                    Case "Currency"
                        fpSpread2_Sheet1.SetActiveCell(13, 2)
                        Exit Select
                    Case "Currency [0]"
                        fpSpread2_Sheet1.SetActiveCell(13, 3)
                        Exit Select
                    Case "Percent"
                        fpSpread2_Sheet1.SetActiveCell(13, 4)
                        Exit Select
                End Select
            End If
        End Sub
    End Class
End Namespace

'
'CellStyles.Designer.vb
'

Namespace Features
	Partial Class CellStyles
		''' <summary> 
		''' Required designer variable.
		''' </summary>
		Private components As System.ComponentModel.IContainer = Nothing

        ''' <summary> 
        ''' Clean up any resources being used.
        ''' </summary>
        ''' <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        Protected Overloads Sub Dispose(disposing As Boolean)
            If disposing AndAlso (components IsNot Nothing) Then
                components.Dispose()
            End If
            MyBase.Dispose(disposing)
        End Sub

#Region "Component Designer generated code"

        ''' <summary> 
        ''' Required method for Designer support - do not modify 
        ''' the contents of this method with the code editor.
        ''' </summary>
        Private Sub InitializeComponent()
			Dim resources As New System.ComponentModel.ComponentResourceManager(GetType(CellStyles))
			Me.splitContainer1 = New System.Windows.Forms.SplitContainer()
			Me.fpSpread2 = New FarPoint.Win.Spread.FpSpread(FarPoint.Win.Spread.LegacyBehaviors.None)
			Me.fpSpread2.OpenExcel("Resource\BuiltInStyles.xlsx", FarPoint.Excel.ExcelOpenFlags.Exchangeable)
			Me.fpSpread2_Sheet1 = Me.fpSpread2.Sheets(0)
			Me.menuStrip1 = New System.Windows.Forms.MenuStrip()
			Me.themeToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
			Me.themeApplyThemeToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
			Me.themeApplyColorSchemeToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
			Me.themeApplyFontSchemeToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
			Me.themeApplyEffectsSchemeToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
			Me.formatCellsToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
			Me.fpSpread1 = New FarPoint.Win.Spread.FpSpread(FarPoint.Win.Spread.LegacyBehaviors.None)
			Me.fpSpread1_Sheet2 = New FarPoint.Win.Spread.SheetView()
			Me.pnlMain.SuspendLayout()
			DirectCast(Me.splitContainer1, System.ComponentModel.ISupportInitialize).BeginInit()
			Me.splitContainer1.Panel1.SuspendLayout()
			Me.splitContainer1.Panel2.SuspendLayout()
			Me.splitContainer1.SuspendLayout()
			DirectCast(Me.fpSpread2, System.ComponentModel.ISupportInitialize).BeginInit()
			Me.menuStrip1.SuspendLayout()
			DirectCast(Me.fpSpread1, System.ComponentModel.ISupportInitialize).BeginInit()
			DirectCast(Me.fpSpread1_Sheet2, System.ComponentModel.ISupportInitialize).BeginInit()
			Me.SuspendLayout()
			' 
			' pnlMain
			' 
			Me.pnlMain.Controls.Add(Me.splitContainer1)
			' 
			' splitContainer1
			' 
			Me.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill
			Me.splitContainer1.Location = New System.Drawing.Point(0, 0)
			Me.splitContainer1.Name = "splitContainer1"
			Me.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal
			' 
			' splitContainer1.Panel1
			' 
			Me.splitContainer1.Panel1.Controls.Add(Me.fpSpread2)
			Me.splitContainer1.Panel1.Controls.Add(Me.menuStrip1)
			' 
			' splitContainer1.Panel2
			' 
			Me.splitContainer1.Panel2.Controls.Add(Me.fpSpread1)
			Me.splitContainer1.Size = New System.Drawing.Size(477, 487)
			Me.splitContainer1.SplitterDistance = 320
			Me.splitContainer1.TabIndex = 3
			' 
			' fpSpread2
			' 
			Me.fpSpread2.Dock = System.Windows.Forms.DockStyle.Fill
			Me.fpSpread2.Location = New System.Drawing.Point(0, 24)
			Me.fpSpread2.Name = "fpSpread2"
			Me.fpSpread2.Size = New System.Drawing.Size(477, 296)
			Me.fpSpread2.TabIndex = 4
			AddHandler Me.fpSpread2.CellClick, New FarPoint.Win.Spread.CellClickEventHandler(AddressOf Me.fpSpread2_CellClick)
			' 
			' menuStrip1
			' 
			Me.menuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.themeToolStripMenuItem, Me.formatCellsToolStripMenuItem})
			Me.menuStrip1.Location = New System.Drawing.Point(0, 0)
			Me.menuStrip1.Name = "menuStrip1"
			Me.menuStrip1.Size = New System.Drawing.Size(477, 24)
			Me.menuStrip1.TabIndex = 3
			Me.menuStrip1.Text = "menuStrip1"
			' 
			' themeToolStripMenuItem
			' 
			Me.themeToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.themeApplyThemeToolStripMenuItem, Me.themeApplyColorSchemeToolStripMenuItem, Me.themeApplyFontSchemeToolStripMenuItem, Me.themeApplyEffectsSchemeToolStripMenuItem})
			Me.themeToolStripMenuItem.Name = "themeToolStripMenuItem"
			Me.themeToolStripMenuItem.Size = New System.Drawing.Size(94, 20)
			Me.themeToolStripMenuItem.Text = "Theme"
			' 
			' themeApplyThemeToolStripMenuItem
			' 
			Me.themeApplyThemeToolStripMenuItem.Name = "themeApplyThemeToolStripMenuItem"
			Me.themeApplyThemeToolStripMenuItem.Size = New System.Drawing.Size(94, 20)
			Me.themeApplyThemeToolStripMenuItem.Text = "Apply Theme..."
			AddHandler Me.themeApplyThemeToolStripMenuItem.Click, New System.EventHandler(AddressOf Me.themeApplyThemeToolStripMenuItem_Clicked)
			' 
			' themeApplyColorSchemeToolStripMenuItem
			' 
			Me.themeApplyColorSchemeToolStripMenuItem.Name = "themeApplyColorSchemeToolStripMenuItem"
			Me.themeApplyColorSchemeToolStripMenuItem.Size = New System.Drawing.Size(94, 20)
			Me.themeApplyColorSchemeToolStripMenuItem.Text = "Apply Color Scheme..."
			AddHandler Me.themeApplyColorSchemeToolStripMenuItem.Click, New System.EventHandler(AddressOf Me.themeApplyColorSchemeToolStripMenuItem_Clicked)
			' 
			' themeApplyFontSchemeToolStripMenuItem
			' 
			Me.themeApplyFontSchemeToolStripMenuItem.Name = "themeApplyFontSchemeToolStripMenuItem"
			Me.themeApplyFontSchemeToolStripMenuItem.Size = New System.Drawing.Size(94, 20)
			Me.themeApplyFontSchemeToolStripMenuItem.Text = "Apply Font Scheme..."
			AddHandler Me.themeApplyFontSchemeToolStripMenuItem.Click, New System.EventHandler(AddressOf Me.themeApplyFontSchemeToolStripMenuItem_Clicked)
			' 
			' themeApplyEffectsSchemeToolStripMenuItem
			' 
			Me.themeApplyEffectsSchemeToolStripMenuItem.Name = "themeApplyEffectsSchemeToolStripMenuItem"
			Me.themeApplyEffectsSchemeToolStripMenuItem.Size = New System.Drawing.Size(94, 20)
			Me.themeApplyEffectsSchemeToolStripMenuItem.Text = "Apply Effects Scheme..."
			AddHandler Me.themeApplyEffectsSchemeToolStripMenuItem.Click, New System.EventHandler(AddressOf Me.themeApplyEffectsSchemeToolStripMenuItem_Clicked)

			' 
			' formatCellsToolStripMenuItem
			' 
			Me.formatCellsToolStripMenuItem.Name = "formatCellsToolStripMenuItem"
			Me.formatCellsToolStripMenuItem.Size = New System.Drawing.Size(94, 20)
			Me.formatCellsToolStripMenuItem.Text = "Format Cells..."
			AddHandler Me.formatCellsToolStripMenuItem.Click, New System.EventHandler(AddressOf Me.formatCellsToolStripMenuItem_Click)
			' 
			' fpSpread1
			' 
			Me.fpSpread1.Location = New System.Drawing.Point(0, 0)
			Me.fpSpread1.Name = "fpSpread1"
			Me.fpSpread1.Sheets.AddRange(New FarPoint.Win.Spread.SheetView() {Me.fpSpread1_Sheet2})
			Me.fpSpread1.Size = New System.Drawing.Size(477, 163)
			Me.fpSpread1.TabIndex = 1
			AddHandler Me.fpSpread1.LeaveCell, New FarPoint.Win.Spread.LeaveCellEventHandler(AddressOf Me.fpSpread1_LeaveCell)
			' 
			' fpSpread1_Sheet2
			' 
			Me.fpSpread1_Sheet2.Reset()
			Me.fpSpread1_Sheet2.SheetName = "Sheet1"
			' Formulas and custom names must be loaded with R1C1 reference style
			Me.fpSpread1_Sheet2.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.R1C1
			Me.fpSpread1_Sheet2.Protect = False
			Me.fpSpread1_Sheet2.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.A1
			' 
			' CellStyles
			' 
			Me.AutoScaleDimensions = New System.Drawing.SizeF(6F, 13F)
			Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
			Me.Name = "CellStyles"
			Me.pnlMain.ResumeLayout(False)
			Me.splitContainer1.Panel1.ResumeLayout(False)
			Me.splitContainer1.Panel1.PerformLayout()
			Me.splitContainer1.Panel2.ResumeLayout(False)
			DirectCast(Me.splitContainer1, System.ComponentModel.ISupportInitialize).EndInit()
			Me.splitContainer1.ResumeLayout(False)
			DirectCast(Me.fpSpread2, System.ComponentModel.ISupportInitialize).EndInit()
			Me.menuStrip1.ResumeLayout(False)
			Me.menuStrip1.PerformLayout()
			DirectCast(Me.fpSpread1, System.ComponentModel.ISupportInitialize).EndInit()
			DirectCast(Me.fpSpread1_Sheet2, System.ComponentModel.ISupportInitialize).EndInit()
			Me.ResumeLayout(False)

		End Sub

		#End Region

		Private splitContainer1 As System.Windows.Forms.SplitContainer
		Private fpSpread2 As FarPoint.Win.Spread.FpSpread
		Private menuStrip1 As System.Windows.Forms.MenuStrip
		Private themeToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
		Private themeApplyThemeToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
		Private themeApplyColorSchemeToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
		Private themeApplyFontSchemeToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
		Private themeApplyEffectsSchemeToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
		Private formatCellsToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
		Private fpSpread1 As FarPoint.Win.Spread.FpSpread
		Private fpSpread1_Sheet2 As FarPoint.Win.Spread.SheetView
		Private fpSpread2_Sheet1 As FarPoint.Win.Spread.SheetView
	End Class
End Namespace
