Search code examples
pythonmetadataxlsx

Getting Last Modified by Name of xlsx file


I have an excel file that gets modified by a group of people and we need to keep track of when the file was last modified and by whom

I was able to retrieve the file properties through .properties but trying to figure out how to isolate the lastModifiedby and insert its value in to a column

from openpyxl import load_workbook
wb = load_workbook('Rec1.xlsx')
wb.properties.lastModifiedBy

It gets me the information I need but I am stumped on how to create a new column "lastmodifiedby" with the information provided in properties


Solution

  • From the documentation: https://openpyxl.readthedocs.io/en/stable/usage.html#write-a-workbook

    Perhaps something like this?

    ws1 = wb.active
    ws1.cell(column=1, row=1, value=wb.properties.lastModifiedBy)
    wb.save(filename='Rec1.xlsx')