Python Forum
Openpyxl manipulate excel write formula
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Openpyxl manipulate excel write formula
#1
Hi all,
I have a demo about calculated each score with target gap as attached, formula is : ='Log'!C3-'Log'!C$2, ='Log'!C4-'Log'!C$2, ='Log'!C5-'Log'!C$2,and stored result in sheet Demo by each row executed .
Actually use formula is ='Log'!C3-'Log'!C2,how to change to except functions(='Log'!C3-'Log'!C$2),any comment will be appreciated!


import openpyxl
from openpyxl import utils

wb=openpyxl.load_workbook("summary.xlsx")
ws=wb['Demo']
ws1=wb['Log']

min_row=ws.min_row
max_row=ws.max_row
min_col=ws.min_column
max_col=ws.max_column

min_row1=ws1.min_row
max_row1=ws1.max_row
min_col1=ws1.min_column
max_col1=ws1.max_column

print(min_row,max_row,min_col,max_col)
print(min_row1,max_row1,min_col1,max_col1)

for row in range(min_row+1,max_row+1):
    for col in range(min_col+1,max_col+1):
        key=ws.cell(row=row,column=col).coordinate
        start=ws.cell(row=2,column=col).coordinate
        end=ws.cell(row=row+1,column=col).coordinate
        print(type(end))
        print(end)
        ws[key]=f'={utils.quote_sheetname(ws1.title)}!{end}-{utils.quote_sheetname(ws1.title)}!{start}'

wb.save('summary.xlsx')
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help using a dynamic array excel formula with XLWings FXMonkey 2 1,277 Jun-06-2023, 09:46 PM
Last Post: FXMonkey
  Excel Automation using Openpyxl pradyumnajpn 1 803 May-16-2023, 09:38 AM
Last Post: Larz60+
  How do I write all csv records to Excel ? Revox 2 949 Mar-29-2023, 03:53 PM
Last Post: deanhystad
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,088 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  how to read txt file, and write into excel with multiply sheet jacklee26 14 9,893 Jan-21-2023, 06:57 AM
Last Post: jacklee26
  {SOLVED]Help getting formula value in Excel to a csv Pedroski55 1 2,006 Sep-20-2021, 12:19 AM
Last Post: Pedroski55
  dataframe write to tab delimited differs from Excel koh 0 1,997 Aug-01-2021, 02:46 AM
Last Post: koh
  Python “Formula” Package: How do I parse Excel formula with a range of cells? JaneTan 1 2,675 Jul-12-2021, 11:09 AM
Last Post: jefsummers
  How do I read in a Formula in Excel and convert it to do the computation in Python? JaneTan 2 2,634 Jul-07-2021, 02:06 PM
Last Post: Marbelous
  Read and write active Excel file euras 4 3,480 Jun-29-2021, 11:16 PM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

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