Excel转换到CSV
#! python3
# ExcelToCSV.py - Excel转换到CSV
import openpyxl, csv, os
for excelfile in os.listdir("."):
# 跳过不是表格的文件
if not excelfile.endswith(".xlsx"):
continue
# 创建对象
wb = openpyxl.load_workbook(excelfile)
csvObj = open(excelfile[0:-4]+".csv","w")
writerObj = csv.writer(csvObj)
for sheetname in wb.sheetnames:
sheet = wb[sheetname]
for rowNum in range(1,sheet.max_row+1):
rowData = []
for colNum in range(1,sheet.max_column+1):
cell = sheet.cell(row=rowNum,column=colNum)
rowData.append(cell.value)
writerObj.writerows([rowData])
# 新式的格式化,就是“%.2f”%(数字)
print("开始搜索|"+excelfile+"|"+sheetname+"|"+
"已完成:{percent:.2f}%".format(percent= (rowNum/sheet.max_row)*100))
csvObj.close()
print("完毕\n============")