Use Cases

Claude Code के साथ Automating Spreadsheet Integration

Claude Code का उपयोग करके automating spreadsheet integration सीखें। Practical tips और code examples शामिल हैं।

スプレッドシートintegrationको Claude Code से Efficient बनाएं

業務システムではExcelやGoogle Sheetsとのdataintegrationが頻繁に発生し है।Claude Code का उपयोग करके、fileの読み書き、data変換、APIintegration तक一気にimplementationでき है।

Excelfileの読み込みと解析

SheetJS(xlsx)を使ったExcelfileの読み込み है।

> xlsxlibraryでExcelfileを読み込んで、型safeなオブジェクト配列に変換するfunctionを作って。
> header行を型のkey के रूप में使って。
import * as XLSX from "xlsx";

export function readExcel<T extends Record<string, unknown>>(
  filePath: string,
  sheetName?: string
): T[] {
  const workbook = XLSX.readFile(filePath);
  const sheet = sheetName
    ? workbook.Sheets[sheetName]
    : workbook.Sheets[workbook.SheetNames[0]];

  if (!sheet) throw new Error(`Sheet not found: ${sheetName}`);

  const data = XLSX.utils.sheet_to_json<T>(sheet, {
    defval: "",
    raw: false,
  });

  return data;
}

// Usage example
interface Employee {
  名पहले: string;
  部署: string;
  メール: string;
  入社日: string;
}

const employees = readExcel<Employee>("./data/employees.xlsx");
console.log(employees);
// [
//   { 名पहले: "田में太郎", 部署: "development部", メール: "[email protected]", 入社日: "2024-04-01" },
//   ...
// ]

Excelfileのgenerate

databaseのdataをExcelに出力するfeatures है।

import * as XLSX from "xlsx";

interface ExportOptions {
  sheetName?: string;
  columnWidths?: number[];
  headerStyle?: boolean;
}

export function createExcel<T extends Record<string, unknown>>(
  data: T[],
  outputPath: string,
  options: ExportOptions = {}
) {
  const { sheetName = "Sheet1", columnWidths } = options;

  const worksheet = XLSX.utils.json_to_sheet(data);

  // column幅のsettings
  if (columnWidths) {
    worksheet["!cols"] = columnWidths.map((w) => ({ wch: w }));
  } else {
    // Auto-calculate width
    const headers = Object.keys(data[0] || {});
    worksheet["!cols"] = headers.map((header) => {
      const maxLen = Math.max(
        header.length * 2, // 日本語は2倍
        ...data.map((row) => String(row[header] || "").length)
      );
      return { wch: Math.min(maxLen + 2, 50) };
    });
  }

  const workbook = XLSX.utils.book_new();
  XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
  XLSX.writeFile(workbook, outputPath);
}

// Usage example
const salesData = [
  { 月: "2026年1月", 売ऊपर: 1200000, 件数: 45 },
  { 月: "2026年2月", 売ऊपर: 1500000, 件数: 52 },
  { 月: "2026年3月", 売ऊपर: 1350000, 件数: 48 },
];

createExcel(salesData, "./output/sales-report.xlsx", {
  sheetName: "売ऊपरレポート",
});

Google Sheets APIとのintegration

Google Sheetsのdataをリアルタイムで読み書きするimplementation है。

import { google } from "googleapis";

const auth = new google.auth.GoogleAuth({
  keyFile: "./credentials.json",
  scopes: ["https://www.googleapis.com/auth/spreadsheets"],
});

const sheets = google.sheets({ version: "v4", auth });

export async function readGoogleSheet(
  spreadsheetId: string,
  range: string
): Promise<string[][]> {
  const response = await sheets.spreadsheets.values.get({
    spreadsheetId,
    range,
  });

  return response.data.values || [];
}

export async function writeGoogleSheet(
  spreadsheetId: string,
  range: string,
  values: (string | number)[][]
) {
  await sheets.spreadsheets.values.update({
    spreadsheetId,
    range,
    valueInputOption: "USER_ENTERED",
    requestBody: { values },
  });
}

export async function appendToGoogleSheet(
  spreadsheetId: string,
  range: string,
  values: (string | number)[][]
) {
  await sheets.spreadsheets.values.append({
    spreadsheetId,
    range,
    valueInputOption: "USER_ENTERED",
    requestBody: { values },
  });
}

// Usage example
const data = await readGoogleSheet("SPREADSHEET_ID", "売ऊपर!A1:D100");
console.log(data);

await appendToGoogleSheet("SPREADSHEET_ID", "売ऊपर!A:D", [
  ["2026年4月", 1400000, 50, "=B5/C5"],
]);

CSVとExcelの相互変換

import * as XLSX from "xlsx";
import fs from "fs";

export function csvToExcel(csvPath: string, excelPath: string) {
  const csv = fs.readFileSync(csvPath, "utf-8");
  const workbook = XLSX.read(csv, { type: "string" });
  XLSX.writeFile(workbook, excelPath);
}

export function excelToCsv(excelPath: string, csvPath: string, sheetIndex = 0) {
  const workbook = XLSX.readFile(excelPath);
  const sheetName = workbook.SheetNames[sheetIndex];
  const csv = XLSX.utils.sheet_to_csv(workbook.Sheets[sheetName]);
  fs.writeFileSync(csvPath, csv);
}

PDF帳票の出力 के साथ combineるcase मेंPDFgeneratefeaturesを、dataの可視化के बारे मेंはdata可視化のimplementationもदेखें。Claude Codeの基本操作はintroduction guideをदेखें。

Summary

Claude Code का उपयोग करके、Excelの読み書き、Google Sheetsintegration、data変換といったスプレッドシート関連のprocessingをकम समय मेंimplementationでき है।業務で頻निकालनाる「DB सेExcel出力」「CSV सेExcel変換」 आदिのpatternは、自然言語で要件を伝える से ही完成し है।

विस्तार से जानने के लिएClaude Codeofficial documentationをदेखें。

#Claude Code #spreadsheet #Excel #Google Sheets #automation