Created
February 2, 2018 18:49
-
-
Save jb221467/08eca03fd1f2b7f0a677603a3d619046 to your computer and use it in GitHub Desktop.
Thumbnails and filenames into Excel spreadsheet
This file contains 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
""" | |
Thumbnails & metadata to Excel | |
Writes images, filenames, and identifiers to an excel file. | |
JPEGs should be no more than 150 pixels on the long edge. | |
Input file is a CSV with columns for 'Filename' and 'Identifier' | |
where 'Filename' values match actual filenames. | |
Last edited 2/2/2018 by Jasmine Burns, [email protected]""" | |
import xlsxwriter | |
import csv | |
inputfile = 'metadata.csv' #change based on metadata csv filename | |
outputfile = 'test.xlsx' #change to desired output filename | |
column2 = 'Identifier' #change based on second column label in inputfile CSV | |
workbook = xlsxwriter.Workbook(outputfile) | |
worksheet = workbook.add_worksheet() | |
worksheet.set_column('A:A',20) | |
with open (inputfile) as csvfile: | |
reader = csv.DictReader(csvfile) | |
wksht = 1 | |
for row in reader: | |
worksheet.set_row(wksht,120) | |
if row['Filename'] == '': | |
worksheet.write('A{0}'.format(wksht),'no image') | |
else: | |
if UserWarning: | |
print('{0} not found'.format(row['Filename'])) | |
worksheet.write('A{0}'.format(wksht),'no image') | |
else: | |
worksheet.insert_image('A{0}'.format(wksht),row['Filename']) | |
worksheet.write('B{0}'.format(wksht),row[column2]) | |
worksheet.write('C{0}'.format(wksht),row['Filename']) | |
wksht = wksht + 1 | |
workbook.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment