使用 openlyxl 访问子目录中的 xlsx 文件。 Python

Accessing xlsx files in a sub directory using openlyxl. Python

所以我有一个文件结构,其中 python 脚本和一个名为 unmerged 的​​目录处于同一级别。在 unmerged 中有一个脚本需要访问的 xlsx 文件。我如何使用 openpyxl 加载该 xlsx 文件。加载工作簿功能似乎只适用于同一级别的文件,所以有没有办法我可以改用路径

编辑:我尝试过的例子

from openpyxl import load_workbook as lw
direc = str(Directory) + "/Unmerged/" + books 
#Directory is fetched from pathlib and books is the file name 
print(direc)
workbook = lw(direc)

这给了我一个错误,因为 lw() 只接受文件名而不是路径

使用相对路径。如果 wb.xslx./my_directory/ 中,则 load_workbook('./my_directory/wb.xlsx')。这不是特定于 openpyxl 的。 This 是路径名的处理方式。