# Format Worksheet — Google Sheets

> Change worksheet-level layout in Google Sheets: freeze header rows or columns, auto-resize columns to fit their contents, set explicit column widths or row heights, hide gridlines, color the sheet tab, or rename the worksheet. Use this…

- Key: `google_sheets-format-worksheet`
- 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/format-worksheet
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/google_sheets/actions/format-worksheet/format-worksheet.mjs

## Description

Change worksheet-level layout in Google Sheets: freeze header rows or columns, auto-resize columns to fit their contents, set explicit column widths or row heights, hide gridlines, color the sheet tab, or rename the worksheet. Use this when a user asks to freeze/lock a header row, make columns wide enough to read, widen or narrow a column, or tidy up a sheet they just uploaded or imported. `autoResizeColumns` is usually what fixes an imported sheet where columns are too narrow and numbers show as `####`. To style the cells themselves (bold, colors, number formats), use **Format Cells**. Use **Get Spreadsheet Info** to discover worksheet names. Example: to lock the header row and fit every column to its content on a freshly imported sheet, call with sheetName="Q3 Revenue", freezeRows=1, autoResizeColumns="ALL" → returns the layout changes applied plus a link to the worksheet. [See the documentation](https://developers.google.com/workspace/sheets/api/samples/rowcolumn)

## 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. |
| `freezeRows` | `integer` | No | Number of rows to freeze at the top so they stay visible while scrolling. Use 1 to freeze a single header row, 0 to unfreeze. |
| `freezeColumns` | `integer` | No | Number of columns to freeze at the left. Use 1 to keep a label column visible while scrolling right, 0 to unfreeze. |
| `autoResizeColumns` | `string` | No | Resize columns to fit their widest value. Pass ALL for every column, or a column reference like A:F or C to limit it. This is the fastest fix for an imported sheet whose columns are too narrow. |
| `columnWidths` | `string` | No | JSON object mapping column references to widths in pixels, e.g. {"A": 240, "C:E": 120}. Use this instead of autoResizeColumns when a specific width is wanted. |
| `rowHeights` | `string` | No | JSON object mapping row references to heights in pixels, e.g. {"1": 40, "2:10": 24}. |
| `hideGridlines` | `boolean` | No | Set true to hide the worksheet's gridlines (a common finishing touch on a report), false to show them. |
| `tabColor` | `string` | No | Color of the worksheet tab, as a hex code (#1155cc) or a common color name (dark blue, green). |
| `newSheetName` | `string` | No | Rename the worksheet to this. Leave empty to keep the current name. |

## 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-format-worksheet",
  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-format-worksheet",
  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-format-worksheet",
    "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
