Share via


WorkbookBase.LinkInfo(String, XlLinkInfo, Object, Object) 方法

定义

获取链接日期和更新状态。

public object LinkInfo (string name, Microsoft.Office.Interop.Excel.XlLinkInfo linkInfoArgument, object type, object editionRef);
member this.LinkInfo : string * Microsoft.Office.Interop.Excel.XlLinkInfo * obj * obj -> obj
Public Function LinkInfo (name As String, linkInfoArgument As XlLinkInfo, Optional type As Object, Optional editionRef As Object) As Object

参数

name
String

链接的名称。

linkInfoArgument
XlLinkInfo

XlLinkInfo 值之一,指定要返回的信息的类型。

type
Object

XlLinkInfoType 值之一,指定要为之返回信息的链接的类型。

editionRef
Object

如果链接为版本,则此参数将版本引用指定为 R1C1 样式的字符串。 EditionRef 如果工作簿中有多个具有相同名称的发布者或订阅者,则是必需的。

返回

指示关于链接的信息的值。 如果 LinkInfoArgumentxlUpdateState,则此方法返回 1(如果链接自动更新)或 2(如果链接必须手动更新)。

示例

下面的代码示例使用 获取当前工作簿中 DDE/OLE 链接的集合,然后使用 LinkInfo 方法确定每个 DDE/OLE 链接是自动更新还是手动更新。

此示例适用于文档级自定义项。

private void WorkbookLinkInfo()
{
    // Get the collection of DDE/OLE links in the workbook.
    Array links = (Array)this.LinkSources(Excel.XlLink.xlOLELinks);

    // If there are DDE/OLE links, then display how each link
    // updates.
    if (links != null)
    {
        for (int i = 1; i <= links.Length; i++)
        {
            string linkName = (string)links.GetValue(i);
            int updateValue = (int)this.LinkInfo(linkName,
                Excel.XlLinkInfo.xlUpdateState,
                Excel.XlLinkInfoType.xlLinkInfoOLELinks);

            if (updateValue == 1)
            {
                MessageBox.Show(linkName + " link updates automatically.");
            }
            else if (updateValue == 2)
            {
                MessageBox.Show(linkName + " link updates manually.");
            }
        }
    }
    else
    {
        MessageBox.Show("The workbook contains no DDE/OLE links.");
    }
}
Private Sub WorkbookLinkInfo()
    ' Get the collection of DDE/OLE links in the workbook.
    Dim Links As Array = _
        CType(Me.LinkSources(Excel.XlLink.xlOLELinks),  _
        Array)

    ' If there are DDE/OLE links, then display how each link
    ' updates.
    If Links IsNot Nothing Then
        Dim i As Integer
        For i = 1 To Links.Length
            Dim UpdateValue As Integer = Me.LinkInfo(Links(i), _
                Excel.XlLinkInfo.xlUpdateState, _
                Excel.XlLinkInfoType.xlLinkInfoOLELinks)

            If UpdateValue = 1 Then
                MsgBox(Links(i) & " link updates automatically.")
            ElseIf UpdateValue = 2 Then
                MsgBox(Links(i) & " link updates manually.")
            End If
        Next i
    Else
        MsgBox("The workbook contains no DDE/OLE links.")
    End If
End Sub

注解

可选参数

有关可选参数的信息,请参阅 Office 解决方案中的可选参数

适用于