Python Forum
Copy certain cells into new workbook certain cells
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Copy certain cells into new workbook certain cells
#1
Hello,

I'm trying to copy certain cells from ws, and paste them into certain cells in ws2, what I have isn't doing this. It's just creating an output file called 'NNM_Comparison.xlsx' which is fine but it has none of the data in it.

import openpyxl as xl; 
import os
 
input_dir = 'C:\\work\\comparison\\NMN'
template = 'C:\\work\\comparison\\template.xlsx'
newFile = 'NNM_Comparison.xlsx'




files = [file for file in os.listdir(input_dir)
         if os.path.isfile(file) and file.endswith(".xlsx")]

for file in files:
    input_file =  os.path.join(input_dir, file)
    wb1=xl.load_workbook(input_file)
    ws=wb1.worksheets[0]
    ws['A1'].value[28:]
    ws['B4'].value
    ws['D4'].value
    ws['B5666'].value
    ws['D5666'].value
	
    wb2 = xl.load_workbook(template) 
    ws2 = wb2.worksheets[0] 
    ws2['A2']==ws['A1']
    ws2['D2']==ws['B4']
    ws2['E2']==ws['D4']
    ws2['I2']==ws['B5666']
    ws2['J2']==ws['D5666']
    
	
    output_file = (newFile)
    wb2.save(output_file)
Reply


Messages In This Thread
Copy certain cells into new workbook certain cells - by Kristenl2784 - Jul-14-2020, 03:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why is the copy method name in python list copy and not `__copy__`? YouHoGeon 2 407 Apr-04-2024, 01:18 AM
Last Post: YouHoGeon
  How to copy work sheet data one workbook to other? sayyedkamran 2 809 Nov-03-2023, 09:10 AM
Last Post: Larz60+
  xlwings error when reading a workbook Mishal0488 1 1,255 Aug-01-2023, 02:05 AM
Last Post: deanhystad
  getting unexpected indent errors trying to move cells up jensengt 4 999 Jun-28-2023, 12:05 PM
Last Post: deanhystad
  Help in opening and editing an excel workbook from a web-browser test 4 1,584 Aug-10-2022, 02:31 PM
Last Post: test
  Converting cells in excel to JSON format desmondtay 4 1,864 May-23-2022, 10:31 AM
Last Post: Larz60+
  Openpyxl-change value of cells in column based on value that currently occupies cells phillipaj1391 5 10,275 Mar-30-2022, 11:05 PM
Last Post: Pedroski55
  gspread - applying ValueRenderOption to a range of cells dwassner 0 1,772 Jan-12-2022, 03:05 PM
Last Post: dwassner
  Python “Formula” Package: How do I parse Excel formula with a range of cells? JaneTan 1 2,801 Jul-12-2021, 11:09 AM
Last Post: jefsummers
  Add a new column when I extract each sheet in an Excel workbook as a new csv file shantanu97 0 2,306 Mar-24-2021, 04:56 AM
Last Post: shantanu97

Forum Jump:

User Panel Messages

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