1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

# ExcelをCSV・JSONに変換する方法まとめ(JavaScript / Python / コピペで使える無料ツール)

1
Last updated at Posted at 2026-08-29

Excelで管理しているデータを、プログラムで扱いやすいCSVやJSONにしたい——APIに流し込む、DBに入れる、Gitで差分を見たい、といった場面でよくある作業です。この記事では、

  • コードで変換する方法(JavaScript / Python
  • コードを書かずにドラッグ&ドロップで一発変換する方法

の両方を、そのまま使える形でまとめます。逆方向(CSV/JSON → Excel)にも触れます。

この記事のゴール:.xlsx を CSV / JSON に(そして必要なら元に戻す)変換できるようになること。


前提:Excelの表は「オブジェクトの配列」になる

1行目を見出し(ヘッダー)とすると、次のExcelは

id name email
1 田中 tanaka@example.com
2 佐藤 sato@example.com

こういうJSON(オブジェクトの配列)に対応します。

[
  { "id": 1, "name": "田中", "email": "tanaka@example.com" },
  { "id": 2, "name": "佐藤", "email": "sato@example.com" }
]
  • 1行目 → キー(見出し)
  • 各行 → 1オブジェクト

CSVなら次の通りです。

id,name,email
1,田中,tanaka@example.com
2,佐藤,sato@example.com

方法1:JavaScriptで変換する(SheetJS)

JavaScriptなら SheetJS(xlsx が定番です。ブラウザでもNode.jsでも動きます。

npm install xlsx
const XLSX = require("xlsx");

// .xlsx を読み込む
const wb = XLSX.readFile("data.xlsx");
const ws = wb.Sheets[wb.SheetNames[0]]; // 先頭シート

// → JSON(オブジェクトの配列)
const json = XLSX.utils.sheet_to_json(ws);
console.log(json);

// → CSV
const csv = XLSX.utils.sheet_to_csv(ws);
console.log(csv);

ブラウザでファイル入力から読む場合は、readFile の代わりに ArrayBuffer を使います。

const buf = await file.arrayBuffer();      // <input type="file">
const wb = XLSX.read(buf, { type: "array" });
const json = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]);

複数シートwb.SheetNames で列挙できます。

wb.SheetNames.forEach((name) => {
  const rows = XLSX.utils.sheet_to_json(wb.Sheets[name]);
  console.log(name, rows.length + "");
});

方法2:Pythonで変換する

pandasを使う(手軽)

pip install pandas openpyxl   # .xlsx読み込みに openpyxl が必要
import pandas as pd

df = pd.read_excel("data.xlsx")   # 先頭シート

# → CSV(Excelで開くなら utf-8-sig で文字化け防止)
df.to_csv("out.csv", index=False, encoding="utf-8-sig")

# → JSON(日本語をそのまま出す)
df.to_json("out.json", orient="records", force_ascii=False, indent=2)

encoding="utf-8-sig" がポイント。BOM付きになるので、書き出したCSVをExcelで開いても日本語が化けません。

標準ライブラリ寄り(openpyxl だけ)

pandasを使いたくない場合はこちら。

import openpyxl, csv, json

wb = openpyxl.load_workbook("data.xlsx")
ws = wb.active
rows = list(ws.iter_rows(values_only=True))
header, body = rows[0], rows[1:]

# → CSV
with open("out.csv", "w", newline="", encoding="utf-8-sig") as f:
    w = csv.writer(f)
    w.writerow(header)
    w.writerows(body)

# → JSON
data = [dict(zip(header, r)) for r in body]
json.dump(data, open("out.json", "w", encoding="utf-8"),
          ensure_ascii=False, indent=2)

方法3:ドラッグ&ドロップで一発変換(コードを書きたくない時)

「1回だけ変換したい」「手元でサッと確認したい」なら、ファイルをドロップするだけのツールが速いです。

私が作っている Morphy の Excel変換なら、

  • Excelを入れてボタンひとつでCSV / JSONに(逆に CSV・JSON → Excel もOK)
  • 複数シートを選択して変換
  • CSVは**UTF-8(BOM付き)**で保存するので、Excelで開いても文字化けしない
  • 処理はすべてブラウザ内で完結し、ファイルは外部に送信されません(社内データでも安心)

登録不要・無料です。オンラインのExcel変換ツールは多くが「ファイルをサーバーにアップロード」する方式ですが、こちらはアップロード自体が発生しません。

👉 Excel ⇄ CSV / JSON 変換ツールhttps://morphytools.com/excel-csv.html


逆方向:CSV / JSON を Excel にする

JavaScript(SheetJS)

const XLSX = require("xlsx");
const data = [
  { id: 1, name: "田中" },
  { id: 2, name: "佐藤" },
];
const ws = XLSX.utils.json_to_sheet(data);
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
XLSX.writeFile(wb, "out.xlsx");

Python(pandas)

import pandas as pd
pd.read_csv("in.csv").to_excel("out.xlsx", index=False)      # CSV → Excel
pd.read_json("in.json").to_excel("out.xlsx", index=False)    # JSON → Excel

まとめ

状況 おすすめ
バッチ処理・自動化に組み込む JavaScript(SheetJS)/ Python
大量データ・分析と合わせて Python(pandas)
1回だけ・手元でサッと ドラッグ&ドロップの無料ツール

特に「今すぐ1回だけ変換したい」「社内のExcelを外部にアップロードしたくない」なら、ブラウザ内で完結するツールが手軽で安全です。

この記事が、Excel⇄CSV/JSON変換の手間を少しでも減らせたら嬉しいです。


1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?