From 4ea7f5d05b4ad62f727f692e0e8b8283351b1437 Mon Sep 17 00:00:00 2001 From: dfinke Date: Sun, 20 Dec 2015 16:37:14 -0500 Subject: [PATCH] Supports auto detect for Hyperlink --- Export-Excel.ps1 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Export-Excel.ps1 b/Export-Excel.ps1 index 6693c06..46406e1 100644 --- a/Export-Excel.ps1 +++ b/Export-Excel.ps1 @@ -170,6 +170,21 @@ function Export-Excel { switch ($TargetData.$Name) { {$_ -is [datetime]} {$targetCell.Style.Numberformat.Format = "m/d/yy h:mm"} } + + [ref]$uriResult=$null + if ([uri]::TryCreate($cellValue, [System.UriKind]::Absolute, $uriResult)) { + + $targetCell.Hyperlink = [uri]$cellValue + + $namedStyle=$ws.Workbook.Styles.NamedStyles | where {$_.Name -eq 'HyperLink'} + if(!$namedStyle) { + $namedStyle=$ws.Workbook.Styles.CreateNamedStyle("HyperLink") + $namedStyle.Style.Font.UnderLine = $true + $namedStyle.Style.Font.Color.SetColor("Blue") + } + + $targetCell.StyleName = "HyperLink" + } $ColumnIndex += 1 }