我在自动化代码时遇到了问题,因此for循环从每个工作表名称的excel文件中提取数据,然后在用python读取该数据后,将其导出到excel文件,并将所有数据放在一个输出文件中,但放在它自己的另一个工作表中。请帮忙。以下是我一直致力于实现这一目标的代码:
for sheet_name in sheets:
file_name = 'DFMECA2.xlsx'
df = pd.set_option('display.max_rows', None)
pd.set_option('display.width', None)
# df = pd.read_excel('DFMECA2.xlsx', sheet_name= sheets[sheet_name]) #read all sheets
df = pd.read_excel('DFMECA2.xlsx', sheet_name=df.sheet_names)
sheet_num = len(sheets)
with pd.ExcelWriter('output2.xlsx') as writer:
df.to_excel(writer, 'sheet1')
df.to_excel(writer, 'sheet2')
df.to_excel(writer, 'sheet3')
df.to_excel(writer, 'sheet4')
df.to_excel(writer, 'sheet5')
df.to_excel(writer, 'sheet6')
df.to_excel(writer, 'sheet7')
df.to_excel(writer, 'sheet8')
df.to_excel(writer, 'sheet9')
df.to_excel(writer, 'sheet10')
df.to_excel(writer, 'sheet11')
df.to_excel(writer, 'sheet12')
df.to_excel(writer, 'sheet13')
暂无答案!
目前还没有任何答案,快来回答吧!