Automating Spreadsheet Integration: Claude Code 활용 가이드
automating spreadsheet integration: Claude Code 활용. 실용적인 팁과 코드 예시를 포함합니다.
スプレッドシート연동をClaude Code로 효율화하기
業務システムではExcelやGoogle Sheetsとの데이터연동が頻繁に発生します。Claude Code를 활용하면 파일の読み書き、데이터変換、API연동まで一気に구현할 수 있습니다。
Excel파일の로딩と解析
SheetJS(xlsx)를 사용한Excel파일の로딩です。
> xlsx라이브러리でExcel파일を読み込んで、타입安全な객체배열に変換する함수を作って。
> 헤더行を타입のキー로서使って。
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);
// [
// { 名前: "田中太郎", 部署: "개발部", メール: "[email protected]", 入社日: "2024-04-01" },
// ...
// ]
Excel파일の생성
데이터베이스の데이터をExcelに출력する機能です。
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);
// カラム幅の설정
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との연동
Google Sheetsの데이터を실시간で読み書きする구현です。
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帳票の출력と組み合わせる場合はPDF생성機能を、데이터の可視化에 대해서는데이터可視化の구현도 확인하세요.Claude Codeの基本操作は入門가이드를 참고하세요.
정리
Claude Code를 활용하면 Excelの読み書き、Google Sheets연동、데이터変換といったスプレッドシート関連の処理を短시간で구현할 수 있습니다。業務で頻出する「DBからExcel출력」「CSVからExcel変換」などのパターンは、自然言語で要件を伝える만으로完成します。
자세한 내용은Claude Code공식 문서를 참고하세요.
무료 PDF: 5분 완성 Claude Code 치트시트
이메일 주소만 등록하시면 A4 한 장짜리 치트시트 PDF를 즉시 보내드립니다.
개인정보는 엄격하게 관리하며 스팸은 보내지 않습니다.
이 글을 작성한 사람
Masa
Claude Code를 적극 활용하는 엔지니어. 10개 언어, 2,000페이지 이상의 테크 미디어 claudecode-lab.com을 운영 중.
관련 글
Claude Code 다국어 글을 매일 발행하기 전에 확인할 7가지
누락된 언어, 깨진 CTA, 반영되지 않은 배포를 막기 위해 다국어 Claude Code 글을 매일 발행하기 전에 확인할 체크리스트입니다.
Codex Automations란? 잠자는 동안 AI가 콘텐츠 운영을 처리하게 하는 방법
Codex Automations로 트래픽 분석, 주제 선정, 글 작성, CTA 개선, 배포까지 자동화하는 실전 가이드.
Claude Code × GCP Cloud Functions 완전 가이드 | 서버리스 함수 초고속 개발
Claude Code로 GCP Cloud Functions를 효율화. HTTP/Pub/Sub/Firestore 트리거 구현부터 로컬 테스트·배포 자동화까지, Masa의 실무 경험을 토대로 실제 코드로 해설.