I would like to extract the required 1 row data (14 cells) from the Excel data, duplicate 12 rows on a new sheet and paste it up to the last row of the original data. I was able to paste it into multiple lines, but the process of repeating it until the last line is not executed. I would like advice on how to do it.
Corresponding source code
What I tried Supplementary information (FW/tool version, etc.)
def act (a): # Function to get the column part for one row for i in range (1,14): # Extract specified 14 cells copy = ws.cell (row = a, column = i) .value copy_prg = ws.cell (row = a, column = 33) .value copy_biko = ws.cell (row = a, column = 34) .value for j in range (1,12): # Duplicate the extracted part in 12 lines ws2.cell (row = j, column = i, value = copy) #Paste all column format parts ws2.cell (row = j, column = 1, value = ws ['K1']. value) # Put k1 in the first column ws2.cell (row = j, column = 14,value = copy_prg) #AG Insert column ws2.cell (row = j, column = 15, value = copy_biko) #AH Insert column (no line break) #The process below does not work max = int (ws.max_row) #Calculation of the number of last rows (221 rows) for y in range (6, max, 4): # Execute while skipping 4 lines from the 6th line to the last line (because lines 1-3 are blank) act (6)
Answer # 1
As pointed out by peterman, act (6) of this process should be act (y).
for y in range (6, max, 4): # Execute while skipping 4 lines from the 6th line to the last line (because lines 1-3 are blank) act (6)
The following process is a paste process, but the line number is fixed.
for j in range (1,12): # Duplicate the extracted part in 12 lines ws2.cell (row = j, column = i, value = copy) #Paste all column format parts
This will always write the values from the 1st line to the 11th line (not 12).
If the original first line is 1-12, the original second line must be written in 13-24, so the argument of range () must be changed according to the value of the original line. ..
The original number of lines is in the variable a. The number of destination lines can be calculated using it.
Answer # 2
I'm not sure about the contents of the act function, but since act (6) is executed every time in the for statement, isn't it incremented? Since the argument does not include y, I think the same process will be repeated.
- about the interpretation of if statements in python
- about writing if statements in dictionaries with python
- python 3x - about downloading anaconda
- python - about "" "of" "" select === = "" "
- python, about the fire spread step of forest fire simulation
- python - about hamiltonian neural networks
- python - about write loop to csv
- about python argument and data definition
- i have a question about basic python problems
- python - about the optimum angle of rotation matrix
- python - about x-axis adjustment in matplotlib
- about processing to exclude the character string group specified from list in python
- python - what i don't understand about yolo9000 (v2)
- about batch change of file name using python
- about the python speedtest code
- about the implementation of combinations in python
- please tell me about the role of python tag = "mychr"
- python - about downloading youtube videos by youtube-dl
- python 3x - please teach about the exchange of information with qthead