using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace iDiTect.Excel.Demo
{
    public static class HyperlinkHelper
    {
        public static void AddHyperlinkToSheet()
        {
            var workbook = new Workbook();
            var worksheet = workbook.Worksheets.Add("HyperlinkSheet");


            //Insert a text hyperlink to external site
            worksheet.Cell("A1").Value = "go to external site";
            worksheet.Cell("A1").Hyperlink = new Hyperlink("https://www.iditect.com", "Go to website");
            //Set hyperlink style
            worksheet.Cell("A1").Style.Font.Underline = FontUnderlineValues.Double;
            worksheet.Cell("A1").Style.Font.FontColor = ExcelColor.Red;

            //Insert a text hyperlink to an address in current worksheet
            worksheet.Cell("A2").Value = "go to B2";
            worksheet.Cell("A2").Hyperlink = new Hyperlink("B2");

            //Insert a text hyperlink to another sheet
            workbook.Worksheets.Add("Worksheet2");
            worksheet.Cell("A3").Value = "go to Worksheet2";
            worksheet.Cell("A3").Hyperlink = new Hyperlink("'Worksheet2'!A1", "go to Worksheet2");

            //Insert a text hyperlink to email
            worksheet.Cell("A4").Value = "go to email";
            worksheet.Cell("A4").Hyperlink.ExternalAddress = new Uri(@"mailto:support@iditect.com");

            //Insert a text hyperlink to a file, both absolute and relative path are support
            worksheet.Cell("A5").Value = "go to external file";
            worksheet.Cell("A5").Hyperlink = new Hyperlink(@"C:\sample.xlsx");

            workbook.Save("hyperlink.xlsx");
        }

    }
}
