Skip to main content

Get-Column-Count

Command Description

Get the number of columns used in the sheet

Command Prototype

iRet = Excel.GetColumsCount(objExcelWorkBook,sheet)

Parameter Description

ParameterRequiredTypeDefaultDescription
objExcelWorkBookTrueexpressionobjExcelWorkBookExcel workbook object (workbook opened with "Open Excel" command (Excel.OpenExcel) or the workbook object returned by the command "Bind Excel" (Excel.BindBook))
sheetTruestring"Sheet1"The string means sheet name. The number means sheet order(starting from 0)

return

iRet,The variable used to save the output of the command.

Demo

/************************Get number of columns************************ ********* 
**Input 1:
** objExcelWorkBook--Excel workbook object (a workbook opened using the "Open Excel" command (Excel.OpenExcel) or a job bound using the "Bind Excel" command (Excel.BindBook) book object).
**Entry 2:
** sheet--If a string is used, it means the name of the specified worksheet; if a number is used, it means the order of the specified worksheet (starting from 0).
**Exports:
** iRet--The variable to which the output of the function call is saved.
**
*********************************************************************/

objExcelWorkBook = Excel.OpenExcel(@res"Test.xlsx",True,"Excel","","")
iRet = Excel.GetColumsCount(objExcelWorkBook,"Sheet1")
TracePrint "Get the number of columns: The number of used columns of the Excel object Sheet1 worksheet is:"&iRet
Excel.CloseExcel(objExcelWorkBook,False)