Syncfusion.XlsIO.Base
Example 


Represents connection source type.
Represents the connection of the table.
Represents destination Range for the query table.

AddEx Method

Creates a query table with specified connection and its source type. Adds it to the IListObjects collection.
Syntax
'Declaration
 
Function AddEx( _
   ByVal type As ExcelListObjectSourceType, _
   ByVal connection As IConnection, _
   ByVal Destination As IRange _
) As IListObject
'Usage
 
Dim instance As IListObjects
Dim type As ExcelListObjectSourceType
Dim connection As IConnection
Dim Destination As IRange
Dim value As IListObject
 
value = instance.AddEx(type, connection, Destination)

Parameters

type
Represents connection source type.
connection
Represents the connection of the table.
Destination
Represents destination Range for the query table.

Return Value

Returns a IListObject with the specified connections.
Remarks
To know more about importing data to table refer Create a Table from External Connection
Example
The following code illustrates how a table can be created using data from external connection.
using Syncfusion.XlsIO;
            
class Program
{
    static void Main()
    {
        using (ExcelEngine excelEngine = new ExcelEngine())
        {
            //Create worksheet
            IApplication application = excelEngine.Excel;
            application.DefaultVersion = ExcelVersion.Excel2013;
            IWorkbook workbook= application.Workbooks.Create(1);
            IWorksheet worksheet = workbook.Worksheets[0];
            
            //Set Connection string for DataSource
            string ConnectionString = "OLEDB;Provider=Microsoft.JET.OLEDB.4.0;Password=\"\";User ID=Admin;Data Source=AccessDB.mdb";
            
            //Add a connection to the workbook
            IConnection Connection = workbook.Connections.Add("Connection1", "Sample connection with MsAccess", ConnectionString, "", ExcelCommandType.Sql);
            
            //Add a QueryTable to sheet object
            IListObject table = worksheet.ListObjects.AddEx(ExcelListObjectSourceType.SrcQuery, Connection, worksheet.Range["A1"]);
            
            //Set Command Text for the Connection
            table.QueryTable.CommandText = "Select * from tbltest";
            
            //Set connection description
            Connection.Description = "Sample Connection";
            
            // Import data to the sheet from the database
            table.Refresh();
            
            //Apply AutoFit
            worksheet.UsedRange.AutofitColumns();
            
            //Save and Dispose
            workbook.SaveAs("Tables.xlsx");
            workbook.Close();
        }
    }
}
AssemblyVersion

Syncfusion.XlsIO.Base: 17.1460.0.47

See Also