---
title: "Cells to Commas action for ActionClip"
canonical_url: "https://actionclip.app/actions/cells-to-commas"
document_type: "standalone_action"
official: true
action_count: 1
catalog_schema_version: 1
catalog_revision: "2026-10-15.5"
catalog_published_at: "2026-10-14T19:51:38Z"
---

# Cells to Commas action for ActionClip

Convert selected spreadsheet cells to CSV, keeping rows and columns.

## What it does

Converts cells from Google Sheets, Excel, or other tab-separated text to CSV. Separates columns with commas and keeps each spreadsheet row on its own line, preserving empty cells within the data and blank rows. Omits completely empty trailing columns. Quotes values containing commas, quotes, or line breaks. Copy the result or use Add to note.

## Action details

| Field | Value |
| --- | --- |
| Category | Text Editing & Formatting |
| Action type | JavaScript |
| Default result | Copy the result |
| Internet | Not required |

## Action and outcome

| Action | Outcome |
| --- | --- |
| **Cells to Commas** — Selected text: Apple Banana Pear Orange | Apple,Banana Pear,Orange |

## How to convert selected spreadsheet cells to CSV, keeping rows and columns with ActionClip

1. Select the text you want to use.
2. Choose **Cells to Commas** from ActionClip.
3. Review the extracted result, then copy it where you need it.

## Requirements

No setup required.

## Privacy

Runs locally in ActionClip’s JavaScript sandbox. Selected text does not leave your Mac.

## Action script

````javascript
function run(selected_text) {
  const rows = [];
  let row = [];
  let cell = "";
  let quoted = false;
  let closedQuote = false;
  let atStart = true;
  const isSeparator = (character) => /[\t\r\n\u000B\u000C\u0085\u2028\u2029]/.test(character);
  const finishCell = () => {
    row.push(cell);
    cell = "";
    closedQuote = false;
    atStart = true;
  };

  for (let index = 0; index < selected_text.length; index += 1) {
    const character = selected_text[index];
    if (quoted) {
      if (character === '"') {
        if (selected_text[index + 1] === '"') {
          cell += '"';
          index += 1;
        } else {
          quoted = false;
          closedQuote = true;
        }
      } else {
        cell += character;
      }
    } else if (isSeparator(character)) {
      finishCell();
      if (character !== "\t") {
        rows.push(row);
        row = [];
      }
      if (character === "\r" && selected_text[index + 1] === "\n") index += 1;
    } else if (closedQuote) {
      throw new Error("Invalid quoted cell. Copy the cell range again and retry.");
    } else if (atStart && character === '"') {
      quoted = true;
      atStart = false;
    } else {
      cell += character;
      atStart = false;
    }
  }
  if (quoted) throw new Error("Incomplete quoted cell. Copy the cell range again and retry.");
  finishCell();

  rows.push(row);
  // Drop only columns that are empty in every selected row.
  let width = rows.reduce((maximum, values) => Math.max(maximum, values.length), 0);
  while (width > 0 && rows.every((values) => (values[width - 1] || "") === "")) width -= 1;
  return rows.map((values) => values.slice(0, width).map((value) =>
    /[,"\t\r\n\u000B\u000C\u0085\u2028\u2029]/.test(value) || value !== value.trim()
      ? '"' + value.replace(/"/g, '""') + '"'
      : value
  ).join(",")).join("\n");
}
````

## Links

- [HTML listing](https://actionclip.app/actions/cells-to-commas)
- [Download action definition](https://actionclip.app/actions/cells-to-commas.actionclip)
- [Browse Text Editing & Formatting actions](https://actionclip.app/marketplace#marketplace-textTools)
- [All Marketplace listings](https://actionclip.app/marketplace)
