# Add Conditional Formatting — Google Sheets

> Add a conditional formatting rule to a range in Google Sheets, so cells style themselves based on their contents — highlight values over a threshold, flag blanks, color-code by text, or apply a red-to-green color scale. Use this when the…

- Key: `google_sheets-add-conditional-formatting`
- Type: Action (Write)
- Version: 0.0.1
- App: Google Sheets (`google_sheets`) — https://pipedream.com/apps/google-sheets.md
- This page (HTML): https://pipedream.com/apps/google-sheets/actions/add-conditional-formatting
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/google_sheets/actions/add-conditional-formatting/add-conditional-formatting.mjs

## Description

Add a conditional formatting rule to a range in Google Sheets, so cells style themselves based on their contents — highlight values over a threshold, flag blanks, color-code by text, or apply a red-to-green color scale. Use this when the user wants formatting driven by the data ('highlight anything over 100', 'make overdue rows red', 'heat-map the revenue column'). For formatting that applies to cells regardless of their value, use **Format Cells** instead. Use **Get Spreadsheet Info** to discover worksheet names and **Read Rows** to see the values you're writing a rule against. `range` is A1 notation WITHOUT the worksheet name (`B2:B100`, `C:C`). `values` supplies the numbers/text the condition compares against: one value for most conditions, two for `NUMBER_BETWEEN`, none for `IS_BLANK`/`IS_NOT_BLANK`/`COLOR_SCALE`, and a formula starting with `=` for `CUSTOM_FORMULA`. Example: to highlight revenue cells above 10000 with a light green fill, call with sheetName="Financials", range="B2:B100", condition="NUMBER_GREATER", values="10000", backgroundColor="light green" → returns the rule that was created and its index on the sheet. [See the documentation](https://developers.google.com/workspace/sheets/api/samples/conditional-formatting)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `spreadsheetId` | `string` | Yes | The spreadsheet ID from the Google Sheets URL. Use List Spreadsheets to find it by name. |
| `sheetName` | `string` | Yes | The worksheet (tab) name. Use Get Spreadsheet Info to discover worksheet names. |
| `range` | `string` | Yes | The cells the rule applies to, in A1 notation and WITHOUT the worksheet name. Examples: B2:B100, C:C (a whole column), A2:F50. Exclude the header row so the header isn't styled by the rule. |
| `condition` | `string` | Yes | What has to be true of a cell for the formatting to apply. COLOR_SCALE is different from the rest: instead of a pass/fail test it shades every cell on a gradient from lowest to highest value, configured with minColor/midColor/maxColor — and it rejects backgroundColor/textColor/bold/italic, which only apply to the pass/fail conditions. |
| `values` | `string` | No | The value(s) the condition compares against. One value for most conditions (10000, Overdue), two comma-separated values for NUMBER_BETWEEN (10,20), none for IS_BLANK, IS_NOT_BLANK and COLOR_SCALE. If a value itself contains a comma, pass a JSON array instead so it isn't split — e.g. ["Smith, John"]. For CUSTOM_FORMULA pass a formula starting with = that is relative to the first cell of the range, e.g. =$D2="Overdue". For DATE_BEFORE/DATE_AFTER pass either a date (2026-09-01) or one of PAST_YEAR, PAST_MONTH, PAST_WEEK, YESTERDAY, TODAY, TOMORROW. |
| `backgroundColor` | `string` | No | Fill color applied to cells that match, as a hex code (#d9ead3) or a common name (light green, light red). Not used by COLOR_SCALE. |
| `textColor` | `string` | No | Font color applied to cells that match. Not used by COLOR_SCALE. |
| `bold` | `boolean` | No | Bold the text of cells that match. Not used by COLOR_SCALE. |
| `italic` | `boolean` | No | Italicize the text of cells that match. Not used by COLOR_SCALE. |
| `minColor` | `string` | No | COLOR_SCALE only — color for the lowest value in the range. Defaults to #ffffff (white). |
| `midColor` | `string` | No | COLOR_SCALE only — color for the median (50th percentile) value. Omit for a two-color scale. |
| `maxColor` | `string` | No | COLOR_SCALE only — color for the highest value in the range. Defaults to #57bb8a (green). |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "google_sheets",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "google_sheets-add-conditional-formatting",
  arguments: {
    spreadsheetId: "Spreadsheet ID",
    sheetName: "Worksheet Name",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "google_sheets-add-conditional-formatting",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    google_sheets: { authProvisionId: "apn_xxxxxxx" },
    spreadsheetId: "Spreadsheet ID",
    sheetName: "Worksheet Name",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "google_sheets-add-conditional-formatting",
    "configured_props": {
      "google_sheets": { "authProvisionId": "apn_xxxxxxx" },
      "spreadsheetId": "Spreadsheet ID",
      "sheetName": "Worksheet Name"
    }
  }'
```

---

- App: https://pipedream.com/apps/google-sheets.md · All apps: https://pipedream.com/apps
