Excel links not loading pages, but when the link is pasted in the browser it works.

前端 未结 3 1216
耶瑟儿~
耶瑟儿~ 2021-01-03 02:47

I have placed hyperlinks in an excel spreadsheet though my ruby-on-rails application. The links are to some privileged pages that require, After the login I am supposed to t

3条回答
  •  暖寄归人
    2021-01-03 03:37

    This is a problem with Excel's internal URL handling, which has issues with modern web design patterns (e.g. sessions + redirects).

    Here's a client-side solution that bypasses Excel's internal mechanisms and uses the OS default URL handler instead. Note that since it uses macros, this approach requires appropriate security settings.

    In your worksheet's VBA module, add the following code:

    Option Explicit
    
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
        ByVal hWnd As Long, _
        ByVal Operation As String, _
        ByVal Filename As String, _
        Optional ByVal Parameters As String, _
        Optional ByVal Directory As String, _
        Optional ByVal WindowStyle As Long = vbMinimizedFocus _
    ) As Long
    
    Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
        ShellExecute 0, "Open", Target.Address
    End Sub
    

    This is based on the answers of two other SO answers.

提交回复
热议问题