简体   繁体   中英

Complete file path of multiple Excel workbooks with Python

I have multiple Excel workbooks open on my computer, which are in different instances. I am using the following script to get the complete path of all the files.

With below code I can get only a list of file names. How can I get the full path?

import xlwings as xw
wb = xw.books
print (wb)

You can get the full path of opened(active) excel file by using this:
If you want then here's the docs , you can explore other options also from docs.

import xlwings as xw
wb = xw.books.active
print(wb.fullname)
"""
C:\Users\...\Desktop\Book1.xlsx
"""

But if you want to get path of all files then:

import xlwings as xw
wb= xw.books
for w in wb:
    print(w.fullname)
"""
C:\Users\...\Desktop\Book1.xlsx
C:\Users\...\Desktop\Book2.xlsx
C:\Users\...\Desktop\Book3.xlsx
"""

Each Book object has a fullname property:

import xlwings

workbooks = xlwings.books
for workbook in workbooks:
    print(workbook.fullname)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM