python xlsx 转csv(格式错乱,不完美版)

import os,sys,openpyxl,csv

os.makedirs("csv",exist_ok=True)

for name in os.listdir("."):

    if not name.endswith(".xlsx"):

        continue

    book=openpyxl.load_workbook(name)

    for i in book.sheetnames:

      sheet=book[i]

      data=[]

      for row in range(1,sheet.max_row+1):

          for column in range(1,sheet.max_column+1):

              data.append(sheet.cell(row=row,column=column).value)

              file=open(os.path.join(".\\csv",name[0:-5]+i+".csv"),"w",newline="")

              writer=csv.writer(file)

              writer.writerow(data)

              file.close()

你可能感兴趣的:(python xlsx 转csv(格式错乱,不完美版))