Skip to main content

Clear-Area

Command Description

Clear the specified area

Command Prototype

Excel.ClearRange(objExcelWorkBook,sheet,strRange,bClearFormat,bSave)

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)
strRangeTruestring"A1:B2"The specified cell, supports two forms: cell names (such as "A1:B2") or two-dimensional array of rows and columns (such as [[cell1 Row number, cell1 column number],[cell2 Row number, cell2 column number]]). When using cell names, it is case insensitive
bClearFormatTruebooleanNoneWhether to clear format of the selected area
bSaveTruebooleanNoneSave immediately after the operation

Demo

/************************Clear Area************************ ******** 
**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).
**Entry 3:
** strRange--Specified range, supports cell names such as "A1:B2" and two-dimensional row and column arrays such as [[cell 1 row number, cell 1 column number], [cell 2 Row number, cell 2 column number]] two forms, case-insensitive when using cell names.
**Entry 4:
** bClearFormat--whether to clear the selected area format. (boolean true/false)
**Entry 5:
** bSave--The operation is completed and saved immediately. (boolean true/false)
**
*********************************************************************/

objExcelWorkBook = Excel.OpenExcel(@res"Test.xlsx",True,"Excel","","")
Excel.ClearRange(objExcelWorkBook,"Sheet1","A1:B2",False,False)
TracePrint "Clear area: Excel object Sheet1'A1:B2' area has data cleared, format retained"
Excel.CloseExcel(objExcelWorkBook,True)