Syncfusion.XlsIO.Base
Example 


Range Property (IConnection)

Represent the connection range.read only
Syntax
'Declaration
 
ReadOnly Property Range As IRange
'Usage
 
Dim instance As IConnection
Dim value As IRange
 
value = instance.Range
IRange Range {get;}
Example
The following code illustrates how the range of the connection can be accessed.
using Syncfusion.XlsIO;
using System;
            
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();
            
            //Get Range
            Console.WriteLine(Connection.Range.AddressLocal.ToString());
            
            //Remove Connection
            Connection.Delete();
            
            //Apply AutoFit
            worksheet.UsedRange.AutofitColumns();
            
            //Save and Dispose
            workbook.SaveAs("Tables.xlsx");
            workbook.Close();
            Console.ReadKey();
        }
    }
}
//Output will be
//A1:A2
AssemblyVersion

Syncfusion.XlsIO.Base: 17.1460.0.32

See Also