Python Forum
Reading Excel files and creating an output
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reading Excel files and creating an output
#1
Hi.

I haven't used Python in a few years and even when I did it was at a very basic level.

I have numerous excel files (e.g. file a.xlsb, b.xlsb) that have been populated and in column "M" there are photo reference numbers (e.g. 1, 2, 43, etc.). I have a folder with all the photos referenced in however there are almost 5000 of them and I need to arrange them into folders as per the excel file (e.g. C:\Pictures\a). The pictures are just numbered the same, 1.jpg, 2.jpg, etc.

The problem I have is that the numbers in the file are not sequential so arranging them manually will take a very long time. Is there a way that I can use python to read the numbers in column M, find the relevant photo in the pictures folder, and then copy those photos into a new folder that corresponds to the file being read?

I hope this makes sense.

Thanks in advance for any help.
Reply
#2
Yes :)

Here's some pseudocode to help:
import shutil
from openpyxl import load_workbook

for file_prefix in ["a", "b"]:
    doc = load_workbook(filename= file_prefix + '.xlsx')
    sheet = doc['Sheet1']

    from_path = './'
    to_path = '/images/' + file_prefix + '/'

    for row in sheet.rows:
        image_id = row['M'] + ".jpg"
        shutil.copyfile(from_path + image_id, to_path + image_id)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Reading and storing a line of output from pexpect child eagerissac 1 4,231 Feb-20-2024, 05:51 AM
Last Post: ayoshittu
  Copy Paste excel files based on the first letters of the file name Viento 2 423 Feb-07-2024, 12:24 PM
Last Post: Viento
  trouble reading string/module from excel as a list popular_dog 0 416 Oct-04-2023, 01:07 PM
Last Post: popular_dog
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,089 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  merge two csv files into output.csv using Subprocess mg24 9 1,757 Dec-11-2022, 09:58 PM
Last Post: Larz60+
  Excel file reading problem max70990 1 891 Dec-11-2022, 07:00 PM
Last Post: deanhystad
  How to loop through all excel files and sheets in folder jadelola 1 4,461 Dec-01-2022, 06:12 PM
Last Post: deanhystad
  Creating csv files from Excel file azizrasul 40 5,582 Nov-03-2022, 08:33 PM
Last Post: azizrasul
Question Export Python output to Excel skyline1397 1 2,034 Jun-26-2022, 05:10 AM
Last Post: skyline1397
  Reading Excel file and use a wildcard in file name and sheet name randolphoralph 6 7,049 Jan-13-2022, 10:20 PM
Last Post: randolphoralph

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020