using NPOI.HSSF.Util;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NPOI
{
class Program
{
static void Main(string[] args)
{
//Load workbook
IWorkbook workbook = new XSSFWorkbook(new FileStream("../../../Data/Sample.xlsx", FileMode.Open));
//Get the first sheet
ISheet sheet = workbook.GetSheetAt(0);
//Set the style of the cell
ICellStyle style = workbook.CreateCellStyle();
IFont font = workbook.CreateFont();
font.Underline = FontUnderlineType.Single;
font.Color = HSSFColor.Red.Index;
font.FontHeight = 15;
style.SetFont(font);
//Add an URL link
ICell cell = sheet.CreateRow(1).CreateCell(1);
cell.SetCellValue("Url link");
XSSFHyperlink UrlLink = new XSSFHyperlink(HyperlinkType.Url)
{
Address = "https://www.e-iceblue.com/"
};
cell.Hyperlink = (UrlLink);
cell.CellStyle = (style);
//Add an e-mail link
cell = sheet.CreateRow(3).CreateCell(1);
cell.SetCellValue("Email link");
XSSFHyperlink MailLink = new XSSFHyperlink(HyperlinkType.Email)
{
Address = "mailto:support@e-iceblue.com"
};
cell.Hyperlink = (MailLink);
cell.CellStyle = (style);
//Add an external file link
cell = sheet.CreateRow(5).CreateCell(1);
cell.SetCellValue("External file link");
XSSFHyperlink FileLink = new XSSFHyperlink(HyperlinkType.File)
{
Address = "ExternalFile.xlsx"
};
cell.Hyperlink = (FileLink);
cell.CellStyle = (style);
//Save the file
FileStream file = File.Create("ExcelHyperlink.xlsx");
workbook.Write(file);
file.Close();
//Launch
System.Diagnostics.Process.Start("ExcelHyperlink.xlsx");
}
}
}