﻿Imports Spread.Common.Features.Spread.Common.Features.Sample

Public Class HyperlinkCells
    Inherits BaseSampleControl

    Sub New()
        InitializeComponent()

        ' initialize fpSpread
        fpSpread1.AllowCellOverflow = True  ' Let cells overflow Like Excel
        fpSpread1.Features.AutoCreateHyperlink = True  ' automatically create hyperlinks With separate undo action
        fpSpread1.Features.EnhancedShapeEngine = True  ' enable enhanced shapes
        fpSpread1.Features.ExcelCompatibleKeyboardShortcuts = True  ' enable New Excel compatible keyboard shortcuts, allows Ctrl+K For Edit Hyperlink dialog
        ' initialize worksheets
        InitializeFormulas()
        InitializeBasicUsage()
        splitContainer1.SplitterDistance = 21  ' Set split To minimum
    End Sub

    Private Sub InitializeBasicUsage()
        Dim ws As IWorksheet = fpSpread1.AsWorkbook().Worksheets(0)
        Dim styles As IStyles = ws.Workbook.Styles ' reuse workbook styles
        ws.Name = "Basic Usage"
        ' initialize cells
        ws.Cells(0, 0, ws.RowCount - 1, ws.ColumnCount - 1).Font.Name = "Calibri"
        ws.Cells(0, 0, ws.RowCount - 1, ws.ColumnCount - 1).Font.Size = 11
        ws.Cells("B2").Text = "Hyperlinks basic usage"
        ws.Cells("B2").Style = styles("title")
        ws.Cells("B4").Text = "Cell Reference Link"
        ws.Cells("B4").Style = styles("exampleTitle")
        ws.Hyperlinks.Add("B5", "", "Formulas!C6", "click here to go to Formulas!C6" + vbCrLf + "Click and hold to select this cell.", "goto Formulas!C6")
        ws.Tables.Add("B4:B5", YesNoGuess.Yes)
        ws.Cells("D4").Text = "Name Reference Link"
        ws.Cells("D4").Style = styles("exampleTitle")
        ws.Workbook.Names.Add("FormulaExample1", "Formulas!$C$6")
        ws.Hyperlinks.Add("D5", "", "FormulaExample1", "click here to go to FormulaExample1" + vbCrLf + "Click and hold to select this cell.", "goto FormulaExample1")
        ws.Tables.Add("D4:D5", YesNoGuess.Yes)
        ws.Cells("F4").Text = "Table Reference Link"
        ws.Cells("F4").Style = styles("exampleTitle")
        ws.Hyperlinks.Add("F5", "", "Table1", "click here to go to Table1", "goto Table1")
        ws.Tables.Add("F4:F5", YesNoGuess.Yes)
        ws.Cells("B7").Text = "Email Link"
        ws.Cells("B7").Style = styles("exampleTitle")
        ws.Hyperlinks.Add("B8", "mailto:spread.support@mescius.com?subject=spread.support", "", "click here to mail for spread support" + vbCrLf + "Click and hold to select this cell.", "Spread support")
        ws.Tables.Add("B7:B8", YesNoGuess.Yes)
        ws.Cells("B10").Text = "Web Link"
        ws.Cells("B10").Style = styles("exampleTitle")
        ws.Hyperlinks.Add("B11", "http:'developer.mescius.com/", "", "click here to go to MESCIUS website" + vbCrLf + "Click and hold to select this cell.", "MESCIUS website")
        ws.Tables.Add("B10:B11", YesNoGuess.Yes)
        ws.Cells("B13").Text = "Shape Link"
        ws.Cells("B13").Style = styles("exampleTitle")
        Dim btn As IShape = ws.Shapes.AddShapeToCell(GrapeCity.Spreadsheet.Drawing.AutoShapeType.ReturnButton, 13, 1, ws.Columns(1).ColumnWidth, ws.Rows(13).RowHeight * 2)
        ws.Hyperlinks.Add(btn, "", "Formulas!C10", "click here to go to Formulas!C10" + vbCrLf + "Right-click to select this shape.")
        ws.Cells("B14:B15").Merge()
        ws.Cells("D13").Text = "Image Link"
        ws.Cells("D13").Style = styles("exampleTitle")
        Dim img As IShape = ws.Shapes.AddPictureToCell("Spread_Eagle_small.png", False, True, 13, 3, 60, 45)
        ws.Hyperlinks.Add(img, "", "Formulas!C14", "click here to go to Formulas!C14\r\nRight-click to select this iamge.")
        ws.Columns("A:F").AutoFit()
        ws.Cells("B17").Text = "Press Ctrl+K to open the Edit Hyperlink dialog\r\nto edit the link in the active cell or selected shape."
        ws.Cells("B17").Style = ws.Workbook.Styles.Add("note", "Note")
    End Sub

    Private Sub InitializeFormulas()
        Dim ws As IWorksheet = fpSpread1.AsWorkbook().Worksheets.Add("Formulas")
        Dim styles As IStyles = ws.Workbook.Styles ' reuse workbook styles
        ' create styles for cells
        Dim titleStyle As IStyle = styles.Add("title")
        titleStyle.IncludeFont = True
        titleStyle.Font.Size = 14
        titleStyle.Font.Bold = True
        Dim formulaLabelStyle As IStyle = styles.Add("formulaLabel")
        formulaLabelStyle.Interior.Color = GrapeCity.Spreadsheet.Color.FromArgb(255, 242, 204)
        formulaLabelStyle.IncludePatterns = True
        Dim resultLabelStyle As IStyle = styles.Add("resultLabel")
        resultLabelStyle.Interior.Color = GrapeCity.Spreadsheet.Color.FromArgb(226, 240, 217)
        resultLabelStyle.IncludePatterns = True
        Dim exampleTitleStyle As IStyle = styles.Add("exampleTitle")
        exampleTitleStyle.Font.Bold = True
        exampleTitleStyle.IncludeFont = True
        Dim formulaExampleStyle As IStyle = styles.Add("formulaExample")
        formulaExampleStyle.Font.Color = GrapeCity.Spreadsheet.Color.FromArgb(192, 0, 0)
        formulaExampleStyle.IncludePatterns = True
        ' initialize cells
        ws.Cells(0, 0, ws.RowCount - 1, ws.ColumnCount - 1).Font.Name = "Calibri"
        ws.Cells(0, 0, ws.RowCount - 1, ws.ColumnCount - 1).Font.Size = 11
        ws.Cells("B2").Text = "HYPERLINK function usage"
        ws.Cells("B2").Style = titleStyle
        ws.Cells("B4").Text = "Cell Reference Link"
        ws.Cells("B4").Style = exampleTitleStyle
        ws.Cells("B5").Text = "Formula"
        ws.Cells("B5").Style = formulaLabelStyle
        ws.Cells("C5").Formula = "FORMULATEXT(C6)"
        ws.Cells("C5").Style = formulaExampleStyle
        ws.Cells("B6").Text = "Result"
        ws.Cells("B6").Style = resultLabelStyle
        ws.Cells("C6").Formula = "HYPERLINK(""#'Basic Usage'!B5"",""goto Basic Usage!B5"")"
        ws.Cells("B8").Text = "Name Reference Link"
        ws.Cells("B8").Style = exampleTitleStyle
        ws.Cells("B9").Text = "Formula"
        ws.Cells("B9").Style = formulaLabelStyle
        ws.Cells("C9").Formula = "FORMULATEXT(C10)"
        ws.Cells("C9").Style = formulaExampleStyle
        ws.Cells("B10").Text = "Result"
        ws.Cells("B10").Style = resultLabelStyle
        ws.Cells("C10").Formula = "HYPERLINK(""#FormulaExample1"",""GoTo FormulaExample1"")"
        ws.Cells("B12").Text = "Table Reference Link"
        ws.Cells("B12").Style = exampleTitleStyle
        ws.Cells("B13").Text = "Formula"
        ws.Cells("B13").Style = formulaLabelStyle
        ws.Cells("C13").Formula = "FORMULATEXT(C14)"
        ws.Cells("C13").Style = formulaExampleStyle
        ws.Cells("B14").Text = "Result"
        ws.Cells("B14").Style = resultLabelStyle
        ws.Cells("C14").Formula = "HYPERLINK(""#Table3"",""GoTo Table3"")"
        ws.Cells("B16").Text = "Email Link"
        ws.Cells("B16").Style = exampleTitleStyle
        ws.Cells("B17").Text = "Formula"
        ws.Cells("B17").Style = formulaLabelStyle
        ws.Cells("C17").Formula = "FORMULATEXT(C18)"
        ws.Cells("C17").Style = formulaExampleStyle
        ws.Cells("B18").Text = "Result"
        ws.Cells("B18").Style = resultLabelStyle
        ws.Cells("C18").Formula = "HYPERLINK(""mailto: spread.support@mescius.com?subject=spread.support"",""Spread support"")"
        ws.Cells("B20").Text = "Email Link"
        ws.Cells("B20").Style = exampleTitleStyle
        ws.Cells("B21").Text = "Formula"
        ws.Cells("B21").Style = formulaLabelStyle
        ws.Cells("C21").Formula = "FORMULATEXT(C22)"
        ws.Cells("C21").Style = formulaExampleStyle
        ws.Cells("B22").Text = "Result"
        ws.Cells("B22").Style = resultLabelStyle
        ws.Cells("C22").Formula = "HYPERLINK(""http'developer.mescius.com/"",""MESCIUS website"")"
        ws.Columns("A:A").AutoFit()
    End Sub
End Class
