使用python将XLSX正确转换为CSV

我正在寻找一个Python库或任何帮助将.XLSX文件转换为.CSV文件。

使用xlrd模块读取您的excel,然后您可以使用csv模块创build您自己的csv。

在命令行中安装xlrd模块:

pip install xlrd

Python脚本:

 import xlrd import csv 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()