Skip to content

Instantly share code, notes, and snippets.

@jb221467
Created February 2, 2018 18:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jb221467/08eca03fd1f2b7f0a677603a3d619046 to your computer and use it in GitHub Desktop.
Save jb221467/08eca03fd1f2b7f0a677603a3d619046 to your computer and use it in GitHub Desktop.
Thumbnails and filenames into Excel spreadsheet
"""
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, jburns@cornell.edu"""
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