• Register

Why .csv file over .xlsx file?

  • CSV is a format for saving table data in a separate text file with the extension .csv while Excel is a spreadsheet that stores files into a related format vls xls or xlsx.
  • CSV is a plain text format with a comma-separated series and Excel is a binary file that stores information for all worksheets.
  • CSV file cannot perform tasks on data while Excel can perform tasks on data.
  • CSV files are faster and use less memory and Excel uses more memory while importing data.
  • CSV files can be opened with any text editor in windows while Excel files can be opened by text editors.

For converting a .xlxs file to a .csv  

  1. You need Python latest version installed in your laptop.
  2. You can get the latest Python file from https://www.python.org/downloads/
  3.  Read your excel file using the xlrd module and then you can use the csv module to create your own new csv.
  4. Install the xlrd module in your command line.

- For installing xlrd module :
Command -> pip install xlrd


Python script:
 

def CSV_from_Excel():
    wb = xlrd.open_workbook('excel.xlsx')
    sh = wb.sheet_by_name('Sheet1')
    your_csv_file = open('your_csv_file.csv', 'w')
    wr = csv.writer(your_csv_file, quoting=csv.QUOTE_ALL)

    for rownum in range(sh.nrows):
        wr.writerow(sh.row_values(rownum))

    your_csv_file.close()

# runs the csv_from_excel function:
CSV_from_Excel()

Conclusion
You can convert any Xlsx sheet into CSV file using the above program by slightly changing the code according to your data. If you have any doubts regarding the article, mention them in the comment section.

530 points
5