拼接excel:
# Section 1import pandas as pdfiles = ['https://github.com/datagy/mediumdata/raw/master/january.xlsx', 'https://github.com/datagy/mediumdata/raw/master/february.xlsx', 'https://github.com/datagy/mediumdata/raw/master/march.xlsx'] combined = pd.DataFrame() # Section 2 for file in files: df = pd.read_excel(file, skiprows = 3) combined = combined.append(df, ignore_index = True) # Section 3 combined.to_excel('combined.xlsx')
从多个表里获取数据:
# Section 1 import openpyxl files = [] #include paths to your files here values = [] # Section 2 for file in files: wb = openpyxl.load_workbook(file) sheet = wb['Sheet1'] value = sheet['F5'].value values.append(value)
跨表格公式:
import openpyxl files = [] # Insert paths to files here for file in files: wb = openpyxl.load_workbook(file) sheet = wb['Sheet1'] sheet['F9'] = '=SUM(F5:F8)' sheet['F9'].style = 'Currency' wb.save(file)
参考链接:https://towardsdatascience.com/automate-these-3-boring-excel-tasks-with-python-666b4ded101b