#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    26
    Rep Power
    0

    Red face Worksheets doesn't get processed when files to be processed are more than 1


    Hi Guys,

    My issue is when ever I copy worksheets from 1 file to another it works, but not from 1 file to multiple files. To elaborate further, if files to be copied are more than 1, copy doesn't work stuck on 1st file, but if listing are reversed last file in list get's copied information. Here is the section of code that gives me problem
    Code:
    	
            str = ''.join(match)
    	for root, dirs, files in os.walk(os.path.abspath(str)):
    		for file in reversed(files):
    			jobno_files_found = os.path.join(root, file)
    			print("files found: ", jobno_files_found)			
    			wb2 = openpyxl.load_workbook(jobno_files_found)
    			print("wb2.sheetnames: ", wb2.sheetnames)
    			for jobno_found in wb2.sheetnames:
    				print("jobno_found: ", jobno_found)
    				temp_sheet = template[jobno_found] #Add Sheet name
    				createData(sheet,temp_sheet,template,jobno_files_found,original_source_wb_row_no)
    The code runs showing all sheets per file when last 2 lines are removed, but when lines are included sheet not found error is coming from code below, which doesn't makes sense since sheets are seen above.
    Code:
    temp_sheet = template[jobno_found] #Add Sheet name
    Any help or advice is greatly appreciated, thanks.
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,486
    Rep Power
    1876
    Does createData() significantly modify the file system, to the point that os.walk() loses the plot?

    Remember that os.walk() is typically a generator, which maintains an internal state and operates 'on demand'.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    26
    Rep Power
    0
    Thanks for your reply salem. createData is just a custom module function used to initiate the copy process, which works for1 file with multiple worksheets, but does copy all worksheets to destination spreadsheet/worksheet when multiple files are to be copied to.
  6. #4
  7. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,972
    Rep Power
    510
    I thought Salem's answer was an insightful shot in the dark.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo