Skip to content

Instantly share code, notes, and snippets.

@aitoehigie
Created February 14, 2022 22:25
Show Gist options
  • Save aitoehigie/efcb48257639bc7382ae21a52fe60a50 to your computer and use it in GitHub Desktop.
Save aitoehigie/efcb48257639bc7382ae21a52fe60a50 to your computer and use it in GitHub Desktop.
import tempfile
import os
import string
import random
import subprocess
import requests
import openai
import pandas as pd
import csv
import openpyxl
def convert_to_csv(file):
if file.endswith('.xlsx') or file.endswith('.xls'):
wb = openpyxl.load_workbook(file)
workbook_sheets = wb.sheetnames
for sheet_name in workbook_sheets:
sheet = wb[sheet_name]
col = csv.writer(open(f"{sheet_name}.csv", "w", newline=""))
for r in sheet.rows:
col.writerow([cell.value for cell in r])
else:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment