I am looking for a python library or any help to convert .XLSX files to .CSV files.
我正在寻找一个python库或任何帮助将. xlsx文件转换成. csv文件。
1 个解决方案
#1
32
Read your excel using the xlrd
module and then you can use the csv
module to create your own csv.
使用xlrd模块读取excel,然后可以使用csv模块创建自己的csv。
Install the xlrd module in your command line:
在命令行中安装xlrd模块:
pip install xlrd
pip安装xlrd
Python script:
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()
#1
32
Read your excel using the xlrd
module and then you can use the csv
module to create your own csv.
使用xlrd模块读取excel,然后可以使用csv模块创建自己的csv。
Install the xlrd module in your command line:
在命令行中安装xlrd模块:
pip install xlrd
pip安装xlrd
Python script:
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()