Class ExcelConnectionCollection
A collection of external connections in a workbook.
Inherited Members
Namespace: OfficeOpenXml.Data.Connection
Assembly: EPPlus.dll
Syntax
public class ExcelConnectionCollection : IEnumerable<ExcelConnection>, IEnumerable
Properties
Count
Number of items in the collection.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| int |
this[int]
Returns the connection at the supplied position.
Declaration
public ExcelConnection this[int index] { get; }
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The index of the connection to return. |
Property Value
| Type | Description |
|---|---|
| ExcelConnection | The connection |
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
Declaration
public ExcelConnection AddDatabase(string name, string connectionString)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name of the connection. |
| string | connectionString | The connection string to the database. |
Returns
| Type | Description |
|---|---|
| ExcelConnection | The connection |
AddOlap(string, string, string)
Adds a connection to a OLAP data source.
Declaration
public ExcelConnection AddOlap(string name, string connectionString, string command)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The uniqe name of the connection |
| string | connectionString | The connection string |
| string | command | The command, usually the name of the qube. |
Returns
| Type | Description |
|---|---|
| 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.
Declaration
public ExcelConnection AddPowerQuery(string name, string connectionString, string mFormula)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name of the connection. |
| string | connectionString | 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="" |
| string | mFormula | 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
| Type | Description |
|---|---|
| ExcelConnection | The connection |
AddText(string, FileInfo)
Adds a connection to a text file data source.
Declaration
public ExcelConnection AddText(string name, FileInfo sourceFile)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name of the connection |
| FileInfo | sourceFile | The path to the text file to use to import external data. Can be expressed in URI or system specific file path notation. |
Returns
| Type | Description |
|---|---|
| ExcelConnection | The connection |
AddText(string, string)
Adds a connection to a text file data source.
Declaration
public ExcelConnection AddText(string name, string sourceFile)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name of the connection |
| string | sourceFile | The path to the text file to use to import external data. Can be expressed in URI or system specific file path notation. |
Returns
| Type | Description |
|---|---|
| ExcelConnection | The connection |
AddWeb(string, string)
Adds a connection to a web query data source.
Declaration
public ExcelConnection AddWeb(string name, string url)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | |
| string | url |
Returns
| Type | Description |
|---|---|
| ExcelConnection | The connection |
GetEnumerator()
The enumerator for the collection.
Declaration
public IEnumerator<ExcelConnection> GetEnumerator()
Returns
| Type | Description |
|---|---|
| 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.
Declaration
public void Remove(ExcelConnection connection)
Parameters
| Type | Name | Description |
|---|---|---|
| ExcelConnection | connection | 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.
Declaration
public void RemoveAt(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The position of the connection to remove. |