I am converting a data table to excel which is working fine. I have 4 columns in data table. Column1 and Column2 are simple text. Column3 and Column4 are hyperlink url and display text. all 4 columns are exported as it is in excel with below code :
string fileName = ConfigurationManager.AppSettings["filename"];
string sheetName = System.IO.Path.GetFileNameWithoutExtension(fileName);
using (XLWorkbook wb = new XLWorkbook())
{
var ws = wb.Worksheets.Add(ptDataTable, sheetName);
ws.Style.Font.FontName = "Arial";
ws.Style.Font.FontSize = 10;
ws.Style.Alignment.WrapText = true;
ws.FirstRow().Style.Alignment.SetWrapText(true);
ws.Style.Alignment.SetWrapText(true);
ws.Style.Alignment.SetShrinkToFit(true);
ws.Style.Alignment.Vertical = XLAlignmentVerticalValues.Top;
ws.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left;
ws.Rows().AdjustToContents();
ws.Columns().AdjustToContents();
ws.Rows(2,200).Style.Fill.SetBackgroundColor((XLColor.Transparent));
ws.Columns(9, 10).Width = 50.0;
ws.Range("A2:J200").Style.Border.SetInsideBorder(XLBorderStyleValues.Thin);
ws.Range("A2:J200").Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin);
using (MemoryStream stream = new MemoryStream())
{
wb.SaveAs(stream);
return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", fileName);
}
}
I want to create hyperlink with column3(url) and column4(display text) and this hyperlink will be 3 column in exported excel.
Any idea!