DDT.ExcelDriver Method

Applies to TestComplete 14.93, last modified on October 12, 2021

Description

Use the ExcelDriver method to create a DDT driver for a sheet of an Excel document. You can use this driver to iterate through the rows of the sheet, obtain values stored in its cells and use these values in your data-driven tests.

Declaration

DDT.ExcelDriver(FileName, Sheet, UseACEDriver)

FileName [in]    Required    String    
Sheet [in]    Required    String    
UseACEDriver [in]    Optional    Boolean Default value: False   
Result A DDTDriver object

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

FileName

String that holds the fully qualified name of the Excel document.

Sheet

String that specifies the name of the desired sheet.

UseACEDriver

If this parameter is True, TestComplete uses the ACE driver to connect to the specified Excel sheet. If the parameter is False, TestComplete connects to the sheet via the Microsoft Excel ODBC driver.

The ACE driver lets you connect to Excel 2007 - 2013 sheets as well as to sheets created in earlier version of Microsoft Excel. The ODBC driver does not support Excel 2007 - 2013. If you have Excel 2007, 2010 or 2013 installed on your workstation, it is recommended that you use the ACE driver.

The 64-bit version of TestComplete ignores this parameter and always uses the 64-bit version of the ACE driver, as if the parameter is set to true. There is no 64-bit version of the ODBC driver, so it can be used with the 64-bit version of TestComplete.

For information on specifics of using these drivers, see Using Excel Files as Data Storages.

Result Value

The DDTDriver object that provides access to data stored in an Excel sheet.

Remarks

The DDT object is available only if the Data-Driven Testing plugin is installed.

For information on working with DDT drivers, see Using DDT Drivers.

For information on specifics and limitations of the Excel DDT driver, see Using Excel Files as Data Storages.

Example

The code below creates a new Excel driver and gets access to its methods and properties via the CurrentDriver property.

JavaScript, JScript

function CurDriverExample()
{
  // Creates a driver
  DDT.ExcelDriver("C:\\MyFile.xls", "Sheet1");
   
  // Iterates through records
  while (! DDT.CurrentDriver.EOF())
  {
  //Gets a value from the storage and posts it to the log
    Log.Message(DDT.CurrentDriver.Value(0));
    DDT.CurrentDriver.Next();
  }
  
  // Closes the driver
  DDT.CloseDriver(DDT.CurrentDriver.Name);
}

Python

def CurDriverExample():
  # Creates a driver 
  DDT.ExcelDriver("C:\\MyFiles\\MyFile.xls", "Sheet1")
  # Iterates through records 
  while not DDT.CurrentDriver.EOF():
    # Gets a value from the storage and posts it to the log 
    Log.Message(DDT.CurrentDriver.Value[0]) 
    DDT.CurrentDriver.Next()
  # Closes the driver 
  DDT.CloseDriver(DDT.CurrentDriver.Name)

VBScript

Sub CurDriverExample
  
  ' Creates a driver
  Call DDT.ExcelDriver("C:\MyFile.xls", "Sheet1")
   
  ' Iterates through records
  While Not DDT.CurrentDriver.EOF()

  ' Gets a value from the storage and posts it to the log
    Log.Message(DDT.CurrentDriver.Value(0))
    DDT.CurrentDriver.Next()
  WEnd
   
  ' Closes the driver
  DDT.CloseDriver(DDT.CurrentDriver.Name)
  
End Sub

DelphiScript

function CurDriverExample;
begin

  // Creates a driver
  DDT.ExcelDriver('C:\MyFile.xls', 'Sheet1');
   
  // Iterates through records
  While Not DDT.CurrentDriver.EOF() do
  begin
  //Gets a value from the storage and posts it to the log
    Log.Message(DDT.CurrentDriver.Value(0));
    DDT.CurrentDriver.Next();
  end;
  
  // Closes the driver
  DDT.CloseDriver(DDT.CurrentDriver.Name);

end;

C++Script, C#Script

function CurDriverExample()
{
  // Creates a driver
  DDT["ExcelDriver"]("C:\\MyFile.xls", "Sheet1");
   
  // Iterates through records
  while (! DDT["CurrentDriver"]["EOF"]())
  {
  //Gets a value from the storage and posts it to the log
    Log.Message(DDT["CurrentDriver"]["Value"](0));
    DDT["CurrentDriver"]["Next"]();
  }
  
  // Closes the driver
  DDT["CloseDriver"]( DDT["CurrentDriver"]["Name"] );
}

See Also

DDTDriver Object
Using DDT Drivers
Using Excel Files as Data Storages
Data-Driven Testing

Highlight search results