Skip to main content

Set-Area-Color

Command Description

Set the color of Designated Area, the property is RGB array, such as [R, G, B]

Command Prototype

Excel.SetRangeColor(objExcelWorkBook,sheet,strRange,listColor,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
listColorTrueexpression[255,255,255]Color in RGB array format
bSaveTruebooleanNoneSave immediately after the operation

Demo

/************************Set area color************************ ********* 
**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:
** listColor-- RGB colors in array form.
**Entry 5:
** bSave--The operation is completed and saved immediately. (boolean true/false)
**
*********************************************************************/

objExcelWorkBook = Excel.OpenExcel(@res"Test.xlsx",True,"Excel","","")
Excel.SetRangeColor(objExcelWorkBook,"Sheet1","A5:B6",[255,0,0],False)
TracePrint "Set the area color: the cells in the area where the Excel object Sheet1'A5:B6' is located are set to red"
Excel.CloseExcel(objExcelWorkBook,True)