话不多说,直接上代码
#导入需要的库
import csv
import openpyxl
import pandas as pd
from openpyxl import load_workbook
#定义方法
def excel_to_csv(excel_file, csv_file):
workbook = load_workbook(filename = excel_file)
sheet = workbook.active
csv_data = []
#Read data from Excel
for value in sheet.iter_rows(values_only = True):
csv_data.append(list(value))
#Write to CSV
with open(csv_file, 'w') as csv_file_obj:
writer = csv.writer(csv_file_obj, delimiter = ',')
for line in csv_data:
writer.writerow(line)
excel_file ='excel表文件路径'
csv_file = '转换后的csv文件存储路径'
excel_to_csv(excel_file, csv_file) #调用方法