首页 > 解决方案 > Python使用密码将多个Excel合二为一

问题描述

当前的python代码没有将数据从多个excel复制到一个主excel,没有错误??有谁知道我做错了什么?

工作表名称 Sheet1

还需要合并我认为我已经完成的密码输入。

import os
import pandas as pd
import openpyxl

cwd = os.path.abspath(r'C:/Users/eldri/OneDrive/Desktop/test/')
cwd = cwd.replace("'\'", "'/'")
files = os.listdir(cwd)
shtname = ('Sheet1')
print (cwd)
print (files)

xltot = pd.DataFrame()
for file in files:  
    if file.endswith('*.xlsx'):
        excel_file.security.workbookPassword = 'password'
        excel_file = pd.ExcelFile(file)
        sheets = excel_file.shtname
        for sheet in sheets: 
            xl = excel_file.parse(shtname)
            xltot = xltot.append(xl)
xltot.to_excel('compiled_xl.xlsx', 'Compiled Excels')
print("Done")

print shows:

    C:\Users\eldri\OneDrive\Desktop\test
    ['cgnbcgnn.xlsx', 'cgncgn.xlsx', 'cgncgnc.xlsx', 'cgng.xlsx', 'fdgfg.xlsx', 'gcncgn.xlsx', 'gcngn.xlsx', 'nfvn.xlsx']

任何帮助都会非常感谢

标签: pythonpandasopenpyxl

解决方案


推荐阅读