Last active
July 22, 2020 19:36
-
-
Save eclecticmiraclecat/5e74bfb68a65380018a56b82c006863c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> import openpyxl | |
>>> import glob | |
>>> | |
>>> update_files = glob.glob('*.xlsx') | |
>>> for i in update_files: | |
... wb = load_workbook(filename=i) | |
... sheet = wb['Sheet1'] | |
... for row in sheet.iter_rows(): | |
... if row[3].value=='4XL' and row[4].value=='8572533': | |
... row[6].value='400' | |
... row[7].value='hola' | |
... wb.save(i) | |
... | |
>>> | |
>>> portfolio = [] | |
>>> with open('blue.csv', 'r') as f: | |
... rows = csv.reader(f) | |
... headers = next(rows) | |
... for row in rows: | |
... record = (row[3],row[6],row[7], row[8]) | |
... portfolio.append(record) | |
>>> for i in update_files: | |
... wb = load_workbook(filename=i) | |
... sheet = wb['Sheet1'] | |
... for row in portfolio: | |
... for xls in sheet.iter_rows(): | |
... if xls[3].value==row[1] and xls[4].value==row[0]: | |
... xls[6].value = 'bbbbbbb' | |
... xls[7].value = 'BLUE' | |
... wb.save(i) | |
... | |
>>> | |
>>> import openpyxl | |
>>> xfile = openpyxl.load_workbook(update_files[0]) | |
>>> sheet = xfile.wb['Sheet1'] | |
>>> xfile['Sheet1']['G4'] = 'hiu' | |
>>> xfile.save(update_files[0]) | |
>>> import openpyxl | |
>>> from openpyxl import load_workbook | |
>>> wb = load_workbook(filename=update_files[0]) | |
>>> wb.sheetnames | |
>>> sheet = wb.active | |
>>> sheet['g4'].value | |
'hiu' | |
>>> for row in sheet.iter_rows(min_col=7, max_col=7): | |
... print(row[0].value) | |
https://stackoverflow.com/a/51335782 | |
# skip loop | |
>>> for a in itertools.islice(sheet.iter_rows(min_col=4, max_col=4), 3, None): | |
... print(a[0].value) | |
https://stackoverflow.com/a/10079247 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment