Faulty Hyperlink to web site using OfficeOpenXml.ExcelHyperLink
Having looked at Doug's sample 'HyperLink.ps1' I found it might be more "excelesk" to use the type OfficeOpenXml.ExcelHyperLink. With that I created a similar script, but I found that instantiating that type is a bit irritating:
- $link=New-Object -TypeName OfficeOpenXml.ExcelHyperLink -ArgumentList ([system.uri]$URL) ; $link.display=$displayname
- $link=New-Object -TypeName OfficeOpenXml.ExcelHyperLink -ArgumentList ([system.uri]$URL),$displayname
While the first code works as expected, the second one initializes ReferenceAddress instead of OriginalUri (which is fine for internal addesses like in Examples/HyperLinks/Races.ps1. Now I wonder whether the second sample really only applies to internal links, or whether I am on the wrong track. Thanks in advance Thomas [Working example below]
remove-item .\test_hyperlink.xlsx -Force
$linkarray=(("http://dougfinke.com/blog","Doug Finke"),("http://blogs.msdn.com/b/powershell/","PowerShell Blog"),("http://blogs.technet.com/b/heyscriptingguy/","Hey, Scripting Guy"))
$al=[System.Collections.ArrayList]@()
foreach($arrayitem in $linkarray){
$rightlink=New-Object -TypeName OfficeOpenXml.ExcelHyperLink -ArgumentList ([system.uri]$arrayitem[0])
$rightlink.display=$arrayitem[1]
$ps=[PSCustomObject]@{
Link = $rightlink
}
$al.add($ps)
}
$al| Export-Excel "test_hyperlink.xlsx" -AutoSize -clearsheet -WorksheetName "Right"
$al.Clear()
foreach($arrayitem in $linkarray){
$wronglink=New-Object -TypeName OfficeOpenXml.ExcelHyperLink -ArgumentList ([system.uri]$arrayitem[0]),$arrayitem[1]
$ps=[PSCustomObject]@{
Link = $wronglink
}
$al.add($ps)
}
$al| Export-Excel "test_hyperlink.xlsx" -AutoSize -Show -clearsheet -WorksheetName "Wrong"
Thanks for the question @TWalijew. Yeah, haven't looked at the hyperlink stuff in a very long time. It was annoying then.
Sorry, don't have an answer.
Thanks, Doug. As I wrote, I could sail around this issue.