Skip to content
Mog is in active development. The GitHub repo, SDK packages, and community channels are not yet available. Follow for launch updates

ws.conditionalFormats

WorksheetConditionalFormatting

Sub-API for conditional formatting operations on a worksheet.

12 methods

add

Promise<string>
add(ranges: CellRange[], rules: CFRuleInput[]): Promise<string>;
ParameterTypeRequired
rangesCellRange[]required
rulesCFRuleInput[]required

Add a new conditional format with ranges and rules. The API assigns IDs and priorities — callers provide rule configuration only. @param ranges - Cell ranges this format applies to @param rules - Rule inputs (without id/priority) @returns The generated format ID

get

Promise<ConditionalFormat | null>
get(formatId: string): Promise<ConditionalFormat | null>;
ParameterTypeRequired
formatIdstringrequired

Get a conditional format by its ID. @param formatId - Format ID to look up @returns The conditional format, or null if not found

update

Promise<void>
update(formatId: string, updates: ConditionalFormatUpdate): Promise<void>;
ParameterTypeRequired
formatIdstringrequired
updatesConditionalFormatUpdaterequired

Update an existing conditional format. Supports replacing rules, ranges, and setting stopIfTrue on all rules. @param formatId - Format ID to update @param updates - Object with optional rules, ranges, and stopIfTrue

clearRuleStyle

Promise<void>
clearRuleStyle(formatId: string, ruleId: string): Promise<void>;
ParameterTypeRequired
formatIdstringrequired
ruleIdstringrequired

Clear the style of a specific rule within a conditional format, resetting all style properties (font, fill, border, number format) to unset. @param formatId - Format ID containing the rule @param ruleId - Rule ID within the format to clear style for

changeRuleType

Promise<void>
changeRuleType(formatId: string, ruleId: string, newRule: CFRuleInput): Promise<void>;
ParameterTypeRequired
formatIdstringrequired
ruleIdstringrequired
newRuleCFRuleInputrequired

Change the type and configuration of a specific rule within a conditional format, preserving its ID and priority. This is the equivalent of OfficeJS's eight changeRuleTo*() methods, unified into one type-safe call using CFRuleInput. @param formatId - Format ID containing the rule @param ruleId - Rule ID to change @param newRule - New rule configuration (type + type-specific fields)

getItemAt

Promise<ConditionalFormat | null>
getItemAt(index: number): Promise<ConditionalFormat | null>;
ParameterTypeRequired
indexnumberrequired

Get a conditional format by its index in the priority-ordered list. @param index - Zero-based index @returns The conditional format at that index, or null if out of bounds

remove

Promise<void>
remove(formatId: string): Promise<void>;
ParameterTypeRequired
formatIdstringrequired

Remove a conditional format by ID. @param formatId - Format ID to remove

list

Promise<ConditionalFormat[]>
list(): Promise<ConditionalFormat[]>;

Get all conditional formats on the sheet. @returns Array of conditional format objects

clear

Promise<void>
clear(): Promise<void>;

Clear all conditional formats from the sheet.

clearInRanges

Promise<void>
clearInRanges(ranges: CellRange[]): Promise<void>;
ParameterTypeRequired
rangesCellRange[]required

Clear conditional formats that intersect with the given ranges. @param ranges - Ranges to clear conditional formats from

reorder

Promise<void>
reorder(formatIds: string[]): Promise<void>;
ParameterTypeRequired
formatIdsstring[]required

Reorder conditional formats by format ID array (first = highest priority). @param formatIds - Array of format IDs in the desired order

cloneForPaste

Promise<void>
cloneForPaste(
    sourceSheetId: string,
    relativeCFs: Array<{
      rules: any[];
      rangeOffsets: Array<{
        startRowOffset: number;
        startColOffset: number;
        endRowOffset: number;
        endColOffset: number;
      }>;
    }>,
    origin: { row: number; col: number },
    isCut: boolean,
  ): Promise<void>;
ParameterTypeRequired
sourceSheetIdstringrequired
relativeCFsArray<{ rules: any[]; rangeOffsets: Array<{ startRowOffset: number; startColOffset: number; endRowOffset: number; endColOffset: number; }>; }>required
origin{ row: number; col: number }required
isCutbooleanrequired

Clone conditional formats from source to target with offset. Used by format painter and paste operations. @param sourceSheetId - Source sheet ID (for cut operation reference removal) @param relativeCFs - Relative CF formats with range offsets @param origin - Target paste origin (row, col) @param isCut - Whether this is a cut operation