Last active
December 5, 2019 04:15
-
-
Save zealinux/e1a2671ee86a1d357d145ff2813c9f74 to your computer and use it in GitHub Desktop.
python xlsx to csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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