I'm trying to write a python script to go through a bunch of XLSX files and make simple, consistent changes to a few cells. I tried using openpyxl which was able to make the changes but deleted the graphs and formatting of the workbook. I've read that win32com.client might be a better library for this but I can't get it on mac. Here's the code I used.
import openpyxl, os, re
from openpyxl import load_workbook
dir = '/Users/work/Desktop/energy_stuff/Rev3-Integrated Reports copy/'
for fil in os.listdir(dir):
if not fil == 'Irvine ES Potential_rev 3_06102014':
if re.search('Combined-15'):
wb = load_workbook(fil)
PD = wb.get_sheet_by_name("PD Inputs-Outputs")
P90 = wb.get_sheet_by_name("P90 Summary")
c = PD.cell('B15')
c.value = '6:00'
d = PD.cell('B16')
d.value = '24:00'
e = P90.cell('B12')
e.value = '9:00'
f = P90.cell('B13')
f.value = '18:00'
wb.save(fil)
if re.search('Combined-60'):
wb = load_workbook(fil)
PD = wb.get_sheet_by_name("PD Inputs-Outputs")
P90 = wb.get_sheet_by_name("P90 Summary")
c = PD.cell('B15')
c.value = '6:00'
d = PD.cell('B16')
d.value = '24:00'
e = P90.cell('B12')
e.value = 9
f = P90.cell('B13')
f.value = 18
wb.save(fil)
else:
print 'Error: Neither Combined-15 nor Combined-60, check file name for typos'
Can anyone recommend a more appropriate library?