共用方式為


WorkbookBase.Connections 屬性

定義

取得活頁簿和資料來源之間連接的集合。

public:
 property Microsoft::Office::Interop::Excel::Connections ^ Connections { Microsoft::Office::Interop::Excel::Connections ^ get(); };
public Microsoft.Office.Interop.Excel.Connections Connections { get; }
member this.Connections : Microsoft.Office.Interop.Excel.Connections
Public ReadOnly Property Connections As Connections

屬性值

Microsoft.Office.Interop.Excel。Connections 集合,其中包含活頁簿與數據源之間的連線。

範例

下列程式代碼範例會將新的數據連線新增至指定的 CSV 檔案。 接下來,此範例會逐一查看活頁簿中存在的所有連線,並顯示每個連線的名稱、類型和描述。 此範例需要在磁碟驅動器 C 根目錄 SalesData.csv 名為 的 CSV 檔案。CSV 檔案應該包含逗號分隔的數據。 當您執行此範例時,Excel 會啟動 文字匯入精靈;請遵循此精靈中的步驟,建立 CSV 檔案的數據連線。

此範例適用於檔層級自定義。

private void WorkbookConnections()
{
    Excel.WorkbookConnection myConnection =
        this.Connections.AddFromFile(@"C:\SalesData.csv");
    myConnection.Description = "Data stored in a CSV file.";

    foreach (Excel.WorkbookConnection connection in this.Connections)
    {
        MessageBox.Show(
            "Connection Name: " + connection.Name 
            + "\r\nConnection Type: " + connection.Type.ToString()
            + "\r\nDescription: " + connection.Description);
    }
}
Private Sub WorkbookConnections()
    Dim myConnection As Excel.WorkbookConnection = _
        Me.Connections.AddFromFile("c:\SalesData.csv")
    myConnection.Description = "Data stored in a CSV file."

    For Each connection As Excel.WorkbookConnection In Me.Connections
        MessageBox.Show(connection.Name + " " + connection.Type.ToString() _
            + " " + connection.Description)
    Next
End Sub

適用於