It is difficult to browse a huge amount of CSV files. I put it together in one Excel file with Python. I often see combining CSV to the same sheet, but I can't find an example of converting 1csv = 1 sheet. I made an article as a memorandum.
ubuntu(wsl) python3.6.8
csvtxlsx.py
import os
import glob
from pathlib import Path
import openpyxl
import csv
csvfiles = glob.glob("(Read source file path)/*.csv", recursive=False)
wb = openpyxl.Workbook()
for file in csvfiles:
wb.create_sheet(os.path.splitext(os.path.basename(file))[0])
wb.active = wb.sheetnames.index(os.path.splitext(os.path.basename(file))[0])
ws = wb.active
with open(file, encoding="shift-jis") as f:
reader = csv.reader(f, delimiter=',')
for row in reader:
ws.append(row)
wb.save("(Output file path)/(Output file name)")
Browsing and handing over files has become easier.
Recommended Posts