Skip to content

Instantly share code, notes, and snippets.

@zealinux
Last active December 5, 2019 04:15
Show Gist options
  • Save zealinux/e1a2671ee86a1d357d145ff2813c9f74 to your computer and use it in GitHub Desktop.
Save zealinux/e1a2671ee86a1d357d145ff2813c9f74 to your computer and use it in GitHub Desktop.
python xlsx to csv
# https://www.studytonight.com/post/converting-xlsx-file-to-csv-file-using-python
# pip install openpyxl
## XLSX TO CSV
import openpyxl
filename = 'appending.xlsx'
## opening the xlsx file
xlsx = openpyxl.load_workbook(filename)
## opening the active sheet
sheet = xlsx.active
## getting the data from the sheet
data = sheet.rows
## creating a csv file
csv = open("data.csv", "w+")
for row in data:
l = list(row)
for i in range(len(l)):
if i == len(l) - 1:
csv.write(str(l[i].value))
else:
csv.write(str(l[i].value) + ',')
csv.write('\n')
## close the csv file
csv.close()
# -----
## XLSX TO CSV
import openpyxl
filename = 'appending.xlsx'
## opening the xlsx file
xlsx = openpyxl.load_workbook(filename)
## opening the active sheet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment