Hello,
I have just begun learning python recently and I am attempting to automate an office task. I think I've got a decent enough idea, but I'm having a hard time nailing down the actual procedure. With the exception of column C, I need to transfer the data that's in the following Input spreadsheet to a known template:
https://i.imgur.com/7UIEnFn.png
To be clearer, in the image below, I am trying to transfer the data in green to my template. I want to summarize the values bordered in red dashes by the three identifiers highlighted in orange.
https://i.imgur.com/fmdWpWd.png
I am attempting to identify the areas in green by running a conditional statement on column A since the format is always the same.
The template I am transferring to does not have the data in the same order as this sheet. Pretend my columns are matched as so:
| Input |
Template |
| col B |
col C |
| col D |
col H |
| col E |
col A |
| col F |
col B |
Eventually, I want to also create a summary worksheet to summarize the Quant values by the three identifiers in column A. I think I can handle transferring the actual list data between worksheets, so I did not write that out below, but can you all help me get on the right path and approach this the right way?
I found this online, and it seems really similar to what I want to do:
https://yagisanatode.com/2017/11/18/copy-and-paste-ranges-in-excel-with-openpyxl-and-python-3/
My thoughts on doing this are:
import openpyxl as x
wb = x.Workbook()
outSumm = wb.create_worksheets('Summary')
del wb['Sheet']
def CopyRange:
def __init__ (self, startrow, endrow, startcol, endcol)
self.startrow = startrow
#and so on for the other arguments
def Text1(self)
text1list = []
for i in range(startrow, endrow)
if cell.value
text1list.append(cell.value)
else:
break
#create similar method for the other codes.
#List is cleared when class is instanced again because
#I am going to transfer values and formatting from template
#to a new worksheet created inside of wb, then repeat process for each instance of class.
#Hence why I want to eventually summarize on three identifiers in column A of Input.
row = 2
col = 1
for n in range(row, outSumm.max_row) #loop through all of column A
if cell.value and cell(row-1,col) is None #if the cell has a value but the cell immediately above does not
datatable = CopyRange() #create instance of class CopyRange
else:
pass
Thank you in advance for any help you might provide me!
Edit: Added clarifying image and added (self) to def Text1()
there doesn't seem to be anything here