Python Forum
[openpyxl] Increment cells being pasted into Template
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[openpyxl] Increment cells being pasted into Template
#3
Hello,

Thanks for the reply everything seems to be working this way, it's a little different then what you had suggested. I'm now stuck on trying to figure out how to look at ws1 column F starting at row 4 and count how many times the value 0 occurs. And then take how many time that value occurs and write it to ws3 column M row 2.


import openpyxl as xl; 
import os
 
input_dir = 'C:\\work\\comparison\\NNM'
template = 'C:\\work\\comparison\\template.xlsx'
summary = 'C:\\work\\comparison\\Summary.xlsx'
newFile = 'Comparison.xlsx'




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


wb3 = xl.load_workbook(template) 
ws3 = wb3.worksheets[0] 

i=0
ii=0


for file in files: 
   input_file =  os.path.join(input_dir, file)
   wb1=xl.load_workbook(input_file)
   ws1=wb1.worksheets[0]

    
   wb2 = xl.load_workbook(summary) 
   ws2 = wb2.worksheets[1]

    
   ws3[f'A{i+2}']=ws1['A1'].value[28:]
   ws3[f'D{i+2}']=ws1['B4'].value
   ws3[f'E{i+2}']=ws1['D4'].value
   ws3[f'I{i+2}']=ws1['B'][-1].value
   ws3[f'J{i+2}']=ws1['D'][-1].value
   ws3[f'O{i+2}']=ws1['E'][-1].value 
   ws3[f'N{i+2}']=ws2[f'I{ii+6}'].value   
   i += 1
   ii +=1          
   
   

   wb3.save(newFile)
Reply


Messages In This Thread
RE: Increment cells being pasted into Template - by Kristenl2784 - Jul-15-2020, 09:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  help to increment a third list hermine 7 1,433 Nov-29-2022, 04:19 PM
Last Post: perfringo
  mysql id auto increment not working tantony 10 2,566 Oct-18-2022, 11:43 PM
Last Post: Pedroski55
  Openpyxl-change value of cells in column based on value that currently occupies cells phillipaj1391 5 10,036 Mar-30-2022, 11:05 PM
Last Post: Pedroski55
  Try,Except,Else to check that user has entered either y or n (Code block pasted) RandomNameGenerator 3 2,374 Jun-29-2021, 08:21 PM
Last Post: RandomNameGenerator
  Character Increment AnokhiRaaz 1 2,531 Apr-22-2021, 04:29 AM
Last Post: buran
  How can I iterate through all cells in a column (with merge cells) with openpyxl? aquerci 1 7,580 Feb-11-2021, 09:31 PM
Last Post: nilamo
  Can you help me to merge the cells with OpenPyXL? TurboC 1 2,242 Feb-01-2021, 12:54 AM
Last Post: Larz60+
  Increment text files output and limit contains Kaminsky 1 3,274 Jan-30-2021, 06:58 PM
Last Post: bowlofred
  Increment formula Kristenl2784 4 2,954 Jul-20-2020, 10:14 PM
Last Post: Kristenl2784
  Copy certain cells into new workbook certain cells Kristenl2784 4 2,529 Jul-14-2020, 07:59 PM
Last Post: Kristenl2784

Forum Jump:

User Panel Messages

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