I'm new to programming and I'm trying to work on a script that will open an excel file in a folder. update the workbook with openpyxl. Save the file. Open the next file in the directory and do the same.
I'm trying this without success:
import os.glob
folder_path = 'G:\\My Drive\\Reports\\'
for filename in glob.glob(os,path.join(folder_path, '*.xlsm')):
with open(filename, 'r' as f:
text = f.read()
print (filename)
print (len(text))
from openpyxl import Workbook
from openpyxl.styles import NamedStyle, Font, Border, Side, Alignment
wb=Workbook()
ws=wb.active
Update cells
wb.save(filename)
Update cellsfor-loop but you do it after leavingfor-loop. BTW: put all imports at the beginning to make it more readable.open(),read()if you want to work with excel files.open(),read()is useful for text files (or similar) butExceluses more complex file and it needs specilized function to read file - and you should useopenpyxlfor this.