Claude Code से स्प्रेडशीट ऑटोमेशन: CSV, Google Sheets API और Apps Script
Claude Code से CSV रिपोर्ट, Google Sheets API और Apps Script वर्कफ़्लो को सुरक्षित ढंग से ऑटोमेट करें।
स्प्रेडशीट ऑटोमेशन छोटी चीज़ लगती है, लेकिन अक्सर वही बिक्री, पूछताछ, विज्ञापन खर्च, इनवॉइस और कंटेंट KPI को जोड़ती है। अगर आयात का नियम गलत हो जाए, तो टीम सिर्फ एक पंक्ति नहीं खोती; वह गलत revenue, गलत priority और गलत campaign decision देखती है।
Claude Code का उपयोग इसलिए करें कि वह repository में काम कर सकता है। वह CSV summary script बना सकता है, Google Sheets API से row जोड़ने वाला script लिख सकता है, Apps Script से lead classification कर सकता है, और अंत में बदली गई files, चलाए गए commands और remaining risks बता सकता है। यही verification इसे production के करीब लाता है।
इस लेख में workflow क्रम से है: पहले local CSV summary, फिर Google Sheets API append, फिर Apps Script classification. मूल आदतों के लिए Claude Code productivity tips और verification receipt workflow भी पढ़ें। official references के लिए Claude Code docs, Claude Code CLI usage, Google Sheets API Node.js quickstart, Apps Script Sheets guide, और SheetJS docs देखें।
पहले data boundary तय करें
पहला सवाल library नहीं है। पहला सवाल है कि source of truth कौन सी table है। अगर वही amount CSV, Google Sheet, CRM और accounting tool में बदल सकता है, तो automation confusion को तेज़ कर देगा। Claude Code को implementation देने से पहले Raw, Clean और Report अलग करें।
| Layer | भूमिका | उदाहरण | Claude Code से क्या बनवाएं |
|---|---|---|---|
| Raw | बिना manual edit का input | form submissions, payment CSV, ad export | import, validation, error rows |
| Clean | type और नाम normal किए data | date, amount, status | normalization, dedupe, required columns |
| Report | human-readable output | monthly revenue, lead priority, KPI | summary, chart CSV, alerts |
सबसे आम गलती Report tab में API से सीधे लिखना है। Report में रंग, formula, notes, frozen rows और human layout होता है। मशीन को stable headers और append-only rows चाहिए। इसलिए program को Raw या Clean में लिखने दें, और Report को formula, pivot, Looker Studio या अलग script से बनाएं।
उदाहरण 1: sales CSV को monthly summary में बदलना
पहले ऐसा काम करें जिसमें Google credential न लगे। इससे Claude Code का output local machine पर verify हो सकता है।
data/sales.csv बनाएं।
date,channel,product,amount,status
2026-05-01,organic,Claude Code Cheatsheet,0,won
2026-05-02,gumroad,Prompt Template Pack,2980,won
2026-05-08,consultation,Team Workshop,120000,won
2026-05-11,gumroad,Prompt Template Pack,2980,refunded
2026-06-01,organic,Claude Code Cheatsheet,0,won
2026-06-02,consultation,Implementation Review,80000,won
scripts/summarize-sales.mjs सेव करें।
import { mkdir, readFile, writeFile } from "node:fs/promises";
import path from "node:path";
const inputPath = process.argv[2] ?? "data/sales.csv";
const outputPath = process.argv[3] ?? "out/monthly-summary.csv";
function parseCsvLine(line) {
const cells = [];
let current = "";
let inQuotes = false;
for (let index = 0; index < line.length; index += 1) {
const char = line[index];
const next = line[index + 1];
if (char === '"' && inQuotes && next === '"') {
current += '"';
index += 1;
continue;
}
if (char === '"') {
inQuotes = !inQuotes;
continue;
}
if (char === "," && !inQuotes) {
cells.push(current.trim());
current = "";
continue;
}
current += char;
}
cells.push(current.trim());
return cells;
}
function parseCsv(source) {
const lines = source.trim().split(/\r?\n/).filter(Boolean);
const headers = parseCsvLine(lines[0]);
return lines.slice(1).map((line) => {
const cells = parseCsvLine(line);
return Object.fromEntries(headers.map((header, index) => [header, cells[index] ?? ""]));
});
}
function toMonth(dateValue) {
const date = new Date(`${dateValue}T00:00:00Z`);
if (Number.isNaN(date.getTime())) {
throw new Error(`Invalid date: ${dateValue}`);
}
return dateValue.slice(0, 7);
}
const rows = parseCsv(await readFile(inputPath, "utf8"));
const summary = new Map();
for (const row of rows) {
if (row.status !== "won") continue;
const amount = Number(row.amount);
if (!Number.isFinite(amount)) {
throw new Error(`Invalid amount: ${JSON.stringify(row)}`);
}
const key = `${toMonth(row.date)},${row.channel}`;
const current = summary.get(key) ?? { month: toMonth(row.date), channel: row.channel, deals: 0, revenue: 0 };
current.deals += 1;
current.revenue += amount;
summary.set(key, current);
}
const output = [
"month,channel,deals,revenue",
...[...summary.values()]
.sort((a, b) => `${a.month}:${a.channel}`.localeCompare(`${b.month}:${b.channel}`))
.map((row) => `${row.month},${row.channel},${row.deals},${row.revenue}`),
].join("\n");
await mkdir(path.dirname(outputPath), { recursive: true });
await writeFile(outputPath, `${output}\n`, "utf8");
console.log(`Wrote ${outputPath} (${summary.size} groups)`);
चलाएं।
mkdir -p data out scripts
node scripts/summarize-sales.mjs data/sales.csv out/monthly-summary.csv
cat out/monthly-summary.csv
महत्वपूर्ण बात है कि खराब data पर script चुपचाप आगे न बढ़े। खाली amount, गलत date या नया status 0 revenue नहीं बनना चाहिए। अगला सुधार यह हो सकता है कि Claude Code row number, rejected CSV और refund tests जोड़े।
उदाहरण 2: Google Sheets API से lead append करना
Team workflow में service account personal OAuth से बेहतर audit trail देता है। Google Cloud में Sheets API enable करें, service account JSON बनाएं, sheet को उस service account email से share करें, और Raw tab में createdAt,source,subject,amount,status headers रखें।
npm install googleapis
export GOOGLE_APPLICATION_CREDENTIALS="$PWD/service-account.json"
export SHEET_ID="your-google-sheet-id"
scripts/append-lead-to-sheet.mjs बनाएं।
import { google } from "googleapis";
const { GOOGLE_APPLICATION_CREDENTIALS, SHEET_ID } = process.env;
if (!GOOGLE_APPLICATION_CREDENTIALS) {
throw new Error("GOOGLE_APPLICATION_CREDENTIALS is required");
}
if (!SHEET_ID) {
throw new Error("SHEET_ID is required");
}
const auth = new google.auth.GoogleAuth({
keyFile: GOOGLE_APPLICATION_CREDENTIALS,
scopes: ["https://www.googleapis.com/auth/spreadsheets"],
});
const sheets = google.sheets({ version: "v4", auth });
const source = process.argv[2] ?? "web";
const subject = process.argv[3] ?? "Claude Code consultation";
const amount = Number(process.argv[4] ?? 0);
if (!Number.isFinite(amount)) {
throw new Error(`Invalid amount: ${process.argv[4]}`);
}
await sheets.spreadsheets.values.append({
spreadsheetId: SHEET_ID,
range: "Raw!A:E",
valueInputOption: "USER_ENTERED",
insertDataOption: "INSERT_ROWS",
requestBody: {
values: [[new Date().toISOString(), source, subject, amount, "new"]],
},
});
console.log("Appended lead row");
चलाने का उदाहरण:
node scripts/append-lead-to-sheet.mjs newsletter "Spreadsheet automation review" 50000
Claude Code से कहें कि environment variables, target range, column order और credentials rule न बदले। service-account.json Git, issue, document या prompt में नहीं जाना चाहिए।
उदाहरण 3: Apps Script से sales और inquiry classify करना
अगर workflow Google Workspace में ही है, Apps Script उपयोगी है। यह form submit पर चल सकता है, Sheet में लिख सकता है और email भेज सकता है। लेकिन quota, trigger, authorization और mail limit हैं। अधिक traffic से पहले Apps Script quotas देखें।
Apps Script editor में code paste करें और onFormSubmit के लिए installable form-submit trigger बनाएं।
const SETTINGS = {
sheetName: "Leads",
notifyTo: "sales@example.com",
minAmountForHighPriority: 100000,
};
function onOpen() {
SpreadsheetApp.getUi()
.createMenu("Lead Ops")
.addItem("Rebuild lead status", "rebuildLeadStatus")
.addToUi();
}
function onFormSubmit(event) {
const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
const sheet = spreadsheet.getSheetByName(SETTINGS.sheetName) || spreadsheet.insertSheet(SETTINGS.sheetName);
ensureHeader_(sheet);
const values = event && event.namedValues ? event.namedValues : {};
const company = first_(values, "Company");
const email = first_(values, "Email");
const plan = first_(values, "Plan");
const budget = Number(first_(values, "Budget") || 0);
const priority = classifyLead_(plan, budget);
sheet.appendRow([new Date(), company, email, plan, budget, priority, "new"]);
if (priority === "high") {
MailApp.sendEmail({
to: SETTINGS.notifyTo,
subject: `High priority lead: ${company}`,
body: `Company: ${company}\nEmail: ${email}\nPlan: ${plan}\nBudget: ${budget}`,
});
}
}
function rebuildLeadStatus() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(SETTINGS.sheetName);
if (!sheet) throw new Error(`Sheet not found: ${SETTINGS.sheetName}`);
ensureHeader_(sheet);
const values = sheet.getDataRange().getValues();
for (let rowIndex = 1; rowIndex < values.length; rowIndex += 1) {
const row = values[rowIndex];
const plan = String(row[3] || "");
const budget = Number(row[4] || 0);
const priority = classifyLead_(plan, budget);
sheet.getRange(rowIndex + 1, 6).setValue(priority);
}
}
function ensureHeader_(sheet) {
const header = ["createdAt", "company", "email", "plan", "budget", "priority", "status"];
const current = sheet.getRange(1, 1, 1, header.length).getValues()[0];
if (current.join("") === "") {
sheet.getRange(1, 1, 1, header.length).setValues([header]);
sheet.setFrozenRows(1);
}
}
function classifyLead_(plan, budget) {
const normalizedPlan = String(plan).toLowerCase();
if (budget >= SETTINGS.minAmountForHighPriority || normalizedPlan.includes("team")) {
return "high";
}
if (budget >= 30000) {
return "medium";
}
return "low";
}
function first_(namedValues, key) {
const value = namedValues[key];
return Array.isArray(value) ? value[0] || "" : "";
}
अगर form fields हिंदी में हैं, तो Company, Plan, Budget को असली labels से बदलें। Claude Code को exact labels दें और कहें कि personal data logs में न लिखे।
Claude Code prompt template
अच्छा prompt छोटा scope और साफ verification देता है।
You are working on spreadsheet automation for this repository.
Goal:
- Import sales CSV rows from data/sales.csv.
- Write a monthly summary to out/monthly-summary.csv.
- Add a Google Sheets append script for the Raw tab.
Scope:
- You may edit scripts/summarize-sales.mjs and scripts/append-lead-to-sheet.mjs.
- You may add small tests or sample CSV files if needed.
- Do not edit content files, product links, analytics, or deployment settings.
Rules:
- Do not commit credentials.
- Use environment variables for SHEET_ID and GOOGLE_APPLICATION_CREDENTIALS.
- Fail loudly on invalid dates, invalid amounts, and missing required columns.
- Keep the code copy-paste runnable with Node.js 20 or later.
Verification:
- Run node --check on every script you edit.
- Run the CSV summary against data/sales.csv.
- For Google Sheets API, verify syntax locally and list the manual credential checks.
- Return changed files, commands run, output summary, and remaining risks.
Verification commands:
node --check scripts/summarize-sales.mjs
node scripts/summarize-sales.mjs data/sales.csv out/monthly-summary.csv
node --check scripts/append-lead-to-sheet.mjs
git diff -- scripts/summarize-sales.mjs scripts/append-lead-to-sheet.mjs
Team में इसे CLAUDE.md में रखें और Claude Code permissions guide के साथ command और file scope तय करें।
व्यावहारिक use cases
पहला use case monthly revenue report है। Gumroad, Stripe, manual invoices और free PDF registrations को CSV में जोड़ें। Refund revenue में न गिने, free lead count में रहे और product names normalize हों।
दूसरा use case lead triage है। Budget, team size, plan और existing customer domain से priority बन सकती है। Rule समझने योग्य होना चाहिए: “budget 100000 yen से अधिक या team plan” review हो सकता है; “अच्छा लग रहा है” review नहीं हो सकता।
तीसरा use case article और ad KPI है। Sheet में slug, publish date, search clicks, CTA clicks, product clicks और consultation starts रखें। Event naming के लिए Claude Code analytics implementation से जोड़ें।
चौथा use case invoice से पहले mismatch check है। Delivery log और invoice CSV मिलाएं और सिर्फ mismatch rows review sheet में लिखें। पहले version में invoice auto-send न करें।
गलतियां जिनसे बचना है
सबसे बड़ी गलती unstable headers हैं। Amount, amount, Revenue अलग-अलग हों तो script पास होकर भी rows छोड़ सकती है। Required headers missing हों तो process fail होना चाहिए।
दूसरी गलती Sheets को database मान लेना है। Sheets collaboration और review के लिए अच्छा है, लेकिन transactions, locking, canonical permissions और massive writes के लिए नहीं। Payments और access rules application database में रहें।
तीसरी गलती credentials leak है। Service account JSON prompts, issues, docs या commits में नहीं जाना चाहिए। Claude Code को secret न पढ़ने, न print करने और न commit करने का निर्देश दें।
चौथी गलती Apps Script trigger भूलना है। Code paste करना काफी नहीं। Installable trigger, execution user, first authorization, mail quota और error notification check करें।
पांचवीं गलती final total ही देखना है। Report में rows read, rows excluded, error count और last updated time होना चाहिए।
CTA: script को operation बनाएं
Spreadsheet automation तभी भरोसेमंद बनती है जब prompts, permissions और verification repeatable हों। शुरुआत free Claude Code cheatsheet से करें। Reusable prompts और CLAUDE.md templates के लिए ClaudeCodeLab products देखें।
अगर team sales, leads, ads या invoices के लिए Sheets इस्तेमाल करती है, तो पहले credential boundary और human approval तय करें। इसे design करने के लिए Claude Code training and consultation उपयोग करें।
असल में आज़माने के बाद
Masa के workflow में सबसे बड़ा लाभ Sheets API से पहले आया: CSV headers, exclusion rules और failure behavior तय करने से। Apps Script lead classification में अच्छा था, लेकिन vague notification rules से emails बहुत बढ़ गए। Stable तरीका यह रहा कि Raw, Clean और Report अलग करें, फिर Claude Code से छोटे हिस्से implement और verify करवाएं।
मुफ़्त PDF: Claude Code cheatsheet
Email डालें और commands, review habits तथा safe workflow वाली एक-page PDF पाएँ.
हम आपका data सुरक्षित रखते हैं और spam नहीं भेजते.
लेखक के बारे में
Masa
Claude Code workflow और team adoption पर काम करने वाला engineer.
संबंधित लेख
Claude Code Obsidian to CLAUDE.md workflow: context बार-बार न समझाएं
Obsidian notes को CLAUDE.md operating notes में बदलकर Claude Code sessions को resume करना आसान बनाएं.
Claude Code Revenue CTA Routing: article से PDF, Gumroad और consultation तक
Reader intent के आधार पर free PDF, Gumroad products और consultation तक CTA route करने वाला workflow.
Claude Code टीम हैंडऑफ नियम: review proof, permissions, rollback और revenue path
Claude Code टीम काम के लिए evidence, permission rules, rollback, free PDF, Gumroad और consultation path वाला handoff.