Need help looping through a directory full of xlsx and xlsm documents and changing set_properties. I have roughly 10k excel files (xlsx & xlsm, no xls files). I am trying to loop through them and change the set_properties. The code I have written makes the correct changes to all documents however when I try to open the documents, all the content (all sheets and everything in each worksheet) is gone. Thanks for your help!
import os
from openpyxl import Workbook
import xlsxwriter
import datetime
os.chdir('C:\\Users\\bayli\\Desktop\\unscrubbed')
mydate = datetime.datetime.now()
files_not_scrubbed = 0
for filename in os.listdir():
if filename.endswith(".xlsx") or filename.endswith(".XLSX") or
filename.endswith(".xlsm") or filename.endswith(".XLSM"):
currentBook = xlsxwriter.Workbook(filename)
currentBook.set_properties({
'title': 'TEST',
'subject': 'TEST',
'author': 'TEST',
'manager': 'TEST',
'company': 'TEST',
'category': 'TEST',
'keywords': 'TEST',
'comments': 'TEST',
'status': 'TEST',
'create': mydate,
})
currentBook.close()
else:
files_not_scrubbed = files_not_scrubbed + 1
continue
print("There were " + str(files_not_scrubbed) + " files not scrubbed.")