DEV Community

Bobo
Bobo

Posted on

How to Convert Excel Files to CSV and JSON Programmatically

How to Convert Excel Files to CSV and JSON Programmatically

Excel files are everywhere. But most programs work better with CSV or JSON. Here's how to bridge the gap.

Method 1: CLI (Fastest)

npm install -g csv-toolkit-pro

# Excel to CSV
csv-toolkit-pro convert input.xlsx -o output.csv

# Excel to JSON (via CSV)
csv-toolkit-pro convert input.xlsx -o temp.csv
csv-toolkit-pro convert temp.csv -o output.json
Enter fullscreen mode Exit fullscreen mode

Method 2: REST API

npm install -g csv-api
csv-api --port 3000 &

curl -X POST http://localhost:3000/convert   -F "file=@report.xlsx"   -F "format=csv"
Enter fullscreen mode Exit fullscreen mode

Method 3: Programmatic

const csvToolkit = require('csv-toolkit');

// Convert Excel to CSV
csvToolkit.convert('report.xlsx', 'report.csv');
Enter fullscreen mode Exit fullscreen mode

One-Liner Conversion

# Convert all Excel files in a folder
csv-toolkit-pro convert ./excel_files/*.xlsx -o ./csv_files/
Enter fullscreen mode Exit fullscreen mode

Supported Formats

csv-toolkit supports:

  • .xlsx (Excel 2007+)
  • .xls (Excel 97-2003)
  • .csv
  • .tsv
  • .json

Install

npm install -g csv-toolkit-pro
Enter fullscreen mode Exit fullscreen mode

🎪 Visit us: https://www.tucaowall.vip/
Get free DigitalOcean credit: https://m.do.co/c/fc5cb7b29a0d
🔧 CLI Toolkit Pro - Unified CLI for devs: Buy $9.99

How do you handle Excel conversions? Share your workflow!

Top comments (0)