ColumnName Property

Applies to TestComplete 15.69, last modified on November 13, 2024

Description

Use the ColumnName property to obtain the column name of a storage for the ProgObj driver. For information on how TestComplete determines the column names, see Using DDT Drivers.

Declaration

ProgObj.ColumnName(Index)

Read-Only Property String
ProgObj An expression, variable or parameter that specifies a reference to one of the objects listed in the Applies To section
Index [in]    Required    Integer    

Applies To

The property is applied to the following object:

Parameters

The property has the following parameter:

Index

Specifies the index of the desired column. Index of the first column is 0, index of the second column - 1, etc. The total number of columns is specified by the ColumnCount property. If the specified column does not exist, an error will occur.

Property Value

String specifying the column name.

Remarks

If you use Python or DelphiScript, you should enclose the parameter of the ProgObj.ColumnName property in square brackets: ProgObj.ColumnName[Index].

When working with Excel files, the Excel DDT driver retrieves data from the ACE driver or the Excel ODBC driver. Due to these driver specifics, the column names are truncated to 64 symbols. To work around this limitation, you can use COM to read column names. For more information on this, see Working With Excel Files via COM. For information on specifics of working with Excel files, see Using Excel Files as Data Storages.

Example

The code below specifies new Excel drivers and then posts the names of all the columns accessed by the driver to the test log.

JavaScript, JScript

function ColumnName()
{
  // Specifies two new Excel drivers
  var Driver = DDT.ExcelDriver("C:\\MyFiles\\1.xls", "Sheet1");
  var ColNum = Driver.ColumnCount;
  
  // Iterates through the columns
  for (var i = 0; i < ColNum; i++)
  {
    var ColName = Driver.ColumnName(i);
    // Posts a column name to the test log
    Log.Message("The name of the " + (i+1) + " column is: " + ColName);
  }
}

Python

def ColumnName():
  # Specifies two new Excel drivers 
  Driver = DDT.ExcelDriver("C:\\MyFiles\\1.xls", "Sheet1")
  ColNum = Driver.ColumnCount
  # Iterates through the columns 
  for i in range(0, ColNum):
    ColName = Driver.ColumnName[i]
    # Posts a column name to the test log 
    Log.Message("The name of the " + str(i + 1) + " column is: " + str(ColName))

VBScript

Sub ColumnName

  ' Specifies two new Excel drivers
  Set Driver = DDT.ExcelDriver("C:\Documents and Settings\User\Desktop\1\1.xls", "Sheet4")
  ColNum = Driver.ColumnCount
  
  ' Iterates through the columns
  For i = 0 to (ColNum - 1)
    ColName = Driver.ColumnName(i)
    ' Posts a column name to the test log
    Log.Message("The name of the " & (i+1) & " column is: " & ColName)
  Next
  
End Sub

DelphiScript

function ColumnName;
var Driver, ColNum, i, ColName;
begin

  // Specifies two new Excel drivers
  Driver := DDT.ExcelDriver('C:\MyFiles\1.xls', 'Sheet1');
  ColNum := Driver.ColumnCount;
  
  // Iterates through the columns
  for i := 0 to (ColNum - 1) do
  begin
    ColName := Driver.ColumnName[i];
    // Posts a column name to the test log
    Log.Message('The name of the ' + IntToStr(i+1) + ' column is: ' + ColName);
  end;

end;

C++Script, C#Script

function ColumnName()
{
  // Specifies two new Excel drivers
  var Driver = DDT["ExcelDriver"]( "C:\\MyFiles\\1.xls", "Sheet1" );
  var ColNum = Driver["ColumnCount"];
  
  // Iterates through the columns
  for (var i = 0; i < ColNum; i++)
  {
    var ColName = Driver["ColumnName"](i);
    // Posts a column name to the test log
    Log["Message"]( "The name of the " + (i+1) + " column is: " + ColName );
  }
}

See Also

ColumnCount Property
Using DDT Drivers

Highlight search results