Skip to main content

Set-Cell-Font-Color

Command Description

Set the font color of the specified unit. The attribute is in the form of array form, such as [R, G, B]

Command Prototype

Excel.SetCellFontColor(objExcelWorkBook,sheet,strCell,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)
strCellTruestring"A1"Two forms of cell are supported: cell names (such as "A1") or array of rows and columns (such as [row number, column number]). It is case-insensitive to use cell names
listColorTrueexpression[255,255,255]Color in RGB array format
bSaveTruebooleanNoneSave immediately after the operation

Demo

/************************Set cell font 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:
** strCell--Specified cell, supports two forms of cell name such as "A1" and row and column array such as [row number, column number]. When using the cell name, it is not case-sensitive.
**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.SetCellFontColor(objExcelWorkBook,"Sheet1","A9",[255,0,0],False)
TracePrint "Set the cell font color: the font of the cell where the Excel object Sheet1'A9' is located is set to red"
Excel.CloseExcel(objExcelWorkBook,True)