import xlwings
app = xlwings.App(visible=True, add_book=False)
for language in ['Java', 'Python', 'C#', 'Vue', "JavaScript"]:
workbook = app.books.add()
workbook.save(f"./畅销开发语言--{language}.xlsx")
import os
import xlwings as xw
app = xw.App(visible=True,add_book=False)
for file in os.listdir("."):
if file.endswith('.xlsx') or file.endswith('.xlsx'):
app.books.open(file)
import xlwings as xw
app = xw.App(visible=False, add_book=False)
workbook = app.books.open("畅销开发语言--Python.xlsx")
for sheet in workbook.sheets:
sheet.name = sheet.name.replace('Sheet', 'ZEN')
workbook.save()
app.quit()
# 合并Excel文件
import pandas as pd
import os
data_list = []
for filename in os.listdir('.'):
if filename.startswith('畅销开发语言--') and filename.endswith('.xlsx'):
# pd.read_excel("xx.xlsx", sheet_name=None)
# sheet_name 默认值0 ,也就是默认打开Excel表中第一个工作簿
data_list.append(pd.read_excel(filename))
data_all = pd.concat(data_list)
data_all.to_excel("合并表.xlsx", index=False)
import pandas as pd
import os
import xlwings as xw
data_list = pd.read_excel("xxx.xlsx", sheet_name=None)
print(data_list)
data_all = pd.concat(data_list.values())
app = xw.App(visible=False, add_book=False)
workbook = app.books.open("xxx.xlsx")
workbook.sheets.add("汇总表", before=workbook.sheets[0])
workbook.sheets["汇总表"].range("A1").options(index=False).value = data_all
workbook.save()
workbook.close()
app.quit()
import pandas as pd
data_list = pd.read_excel("xxx.xlsx", sheet_name=0)
courses = data_list["course"].unique()
for course in courses:
data_single = data_list[data_list["course"] == course]
data_single.to_excel(f"拆分数据-{course}.xlsx")