Reading book properties using python and xlrd

Is there any way to read excel file properties using xlrd? I do not mean the properties of the cell view, but the general properties of the workbook.

Thank you very much in advance.

+4
source share
2 answers

Besides the username (the last person to save the worksheet), the book instance returned by open_workbook does not seem to have any properties.

I recursively dropped the book (dropping its dict if xlrd.BaseObject), and couldn't find anything that way. Of course, the test files were by author, company, and some user metadata.

FWIW: LibreOffice doesn't seem to be able to find the author and company either (or doesn't display them), but it also shows custom metadata in the properties.

+1
source

I could not find a way to do this with xlrd, but if you only need to read .xlsx files, you can treat them as Zipfiles and read XML property files. You can see this by changing the .xlsx extension to .zip and opening the file on Windows. The following is an example of reading custom properties.

from lxml import etree as ET import zipfile def get_custom_properties(filename): zip = zipfile.ZipFile(filename) props = zip.open('docProps/custom.xml') text = props.read() xml = ET.fromstring(text) # Works on my example document, but I don't know if every # child node will always have exactly one nested node return { child.attrib['name']: child[0].text for child in xml } 
0
source

Source: https://habr.com/ru/post/1442989/


All Articles