Skip to content

Class ExcelConnectionCollection

Namespace: OfficeOpenXml.Data.Connection
Assembly: EPPlus.dll

A collection of external connections in a workbook.

public class ExcelConnectionCollection : IEnumerable<ExcelConnection>, IEnumerable

Inheritance

object ← ExcelConnectionCollection

Implements

IEnumerable
IEnumerable<ExcelConnection>

Inherited Members

object.Equals(object?, object?)
object.Equals(object?)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object?, object?)
object.ToString()

Properties

Count

Number of items in the collection.

public int Count { get; }

Property Value

int

this[int]

Returns the connection at the supplied position.

public ExcelConnection this[int index] { get; }

Property Value

ExcelConnection

Methods

AddDatabase(string, string)

Adds a connection of type database with the specified connection string. EPPlus will set the Type of the connection to Odbc or OleDb, depending on the connection string. If you use another type, please set it manually. If the connection string is a power querty connection string, please also see PowerQuerySettings

public ExcelConnection AddDatabase(string name, string connectionString)

Parameters

name string

The name of the connection.

connectionString string

The connection string to the database.

Returns

ExcelConnection

The connection

AddOlap(string, string, string)

Adds a connection to a OLAP data source.

public ExcelConnection AddOlap(string name, string connectionString, string command)

Parameters

name string

The uniqe name of the connection

connectionString string

The connection string

command string

The command, usually the name of the qube.

Returns

ExcelConnection

The connection

AddPowerQuery(string, string, string)

Adds a power query connection with the specified connection string. EPPlus will set the Type of the connection to OleDb. A power query connection requires a connection string with the OleDb provide Microsoft.Mashup.OleDb.1 and a M-Formula containing the query. The PowerQuerySettings property will be created, if it does not exist.

public ExcelConnection AddPowerQuery(string name, string connectionString, string mFormula)

Parameters

name string

The name of the connection.

connectionString string

The connection string to the database. Power query connection string usually uses the Microsoft.Mashup.OleDb.1 OleDb provider. For example: Provider=Microsoft.Mashup.OleDb.1;Data Source=\(Workbook\);Location="Table 1";Extended Properties=""

mFormula string

The M formulas to use for the power query connection, without the Section1 declaration. This formula is appended to the Formulas property of the PowerQuerySettings object.

Returns

ExcelConnection

The connection

AddText(string, FileInfo)

Adds a connection to a text file data source.

public ExcelConnection AddText(string name, FileInfo sourceFile)

Parameters

name string

The name of the connection

sourceFile FileInfo

The path to the text file to use to import external data. Can be expressed in URI or system specific file path notation.

Returns

ExcelConnection

The connection

AddText(string, string)

Adds a connection to a text file data source.

public ExcelConnection AddText(string name, string sourceFile)

Parameters

name string

The name of the connection

sourceFile string

The path to the text file to use to import external data. Can be expressed in URI or system specific file path notation.

Returns

ExcelConnection

The connection

AddWeb(string, string)

Adds a connection to a web query data source.

public ExcelConnection AddWeb(string name, string url)

Parameters

name string

url string

Returns

ExcelConnection

The connection

GetEnumerator()

The enumerator for the collection.

public IEnumerator<ExcelConnection> GetEnumerator()

Returns

IEnumerator<ExcelConnection>

The enmerator

Remove(ExcelConnection)

Removes the connection at the given position. Please note that any related Power Query formula is not removed from the Formulas by this method.

public void Remove(ExcelConnection connection)

Parameters

connection ExcelConnection

The connection to remove.

RemoveAt(int)

Removes the connection at the given position. Please note that any related Power Query formula is not removed for the Formulas by this method.

public void RemoveAt(int index)

Parameters

index int

The position of the connection to remove.