ist ich eine Antwort habe die Bereitstellung, das zeigt, wie Sie erreichen können dies mit xlsxwriter. Es erstellt eine Tabelle, die den Namen und die ID sowie eine Verknüpfung zum zugehörigen Bild in drei separaten Spalten enthält.
Die Antwort verwendet urllib.request, so dass es reproduzierbar ist (dieses Modul ist nicht erforderlich, ich habe es nur dort, um drei Testbilder herunterladen). Ich habe das Verzeichnis auch auf das aktuelle Verzeichnis gesetzt, das Sie beliebig ändern können. Außerdem habe ich in meiner Antwort festgelegt, dass nur nach .png-Dateien gesucht wird. Sie können jedoch auch nach anderen Dateiformaten suchen.
import urllib.request
import xlsxwriter
import os
#comment out the next 4 lines if you don't want to download 3 pictures
url = 'https://upload.wikimedia.org/wikipedia/en/thumb/4/43/Ipswich_Town.svg/255px-Ipswich_Town.svg.png'
urllib.request.urlretrieve(url, "pica_1.png")
urllib.request.urlretrieve(url, "picb_2.png")
urllib.request.urlretrieve(url, "picc_3.png")
dir_wanted = os.getcwd()
#uncomment the following line if you don't want the current directory
#dir_wanted = "C:\\users\\doe_j"
file_list = [file for file in os.listdir(dir_wanted) if file.endswith('.png')]
full_path_list = [dir_wanted + '\\' + file for file in file_list]
name_list = []
num_list = []
for item in file_list:
temp_list = item.rpartition('_')
name = str(temp_list[0])
num = str(temp_list[2].rpartition('.')[0])
name_list.append(name)
num_list.append(num)
workbook = xlsxwriter.Workbook('pics_and_links.xlsx')
ws = workbook.add_worksheet('Links')
#adding column titles and making them bold
bold = workbook.add_format({'bold': True})
ws.write('A1', "Name", bold)
ws.write('B1', "Number", bold)
ws.write('C1', "Link", bold)
#putting the three lists we made into the workbook
for i in range (0, len(full_path_list)):
row_num = i + 2
ws.write('A%d' % row_num, name_list[i])
ws.write('B%d' % row_num, int(num_list[i]))
ws.write_url('C%d' % row_num, full_path_list[i])
#Set the width of the column with the links in it
ws.set_column(2, 2, 40)
workbook.close()
Vielen Dank, Sie haben mir wirklich dabei geholfen! – Grantler
Großartig. Froh, dass es geholfen hat. – patrickjlong1