how to use openpyxl to do ‘select’ and ‘fill down’ like in an excel file

I am having a lot of success using openxpyxl to do many operations. I have a table of dates, numbers and formulas that I insert a new row within the table and enter some easy data (date, name, amount) but I am having trouble with columns that have simple formulas like cell F7 would be ‘=F6+C7’. F8 would be ‘=F7+C8’ etc down the table. When I insert the new (empty) row in the middle of the table, the rows below the insertrow do not get updated with the correct indexed. For example F24 becomes ‘=F22+C23’ instead of incrementing to ‘=F23+C24’ like it would do if I used an excel ‘fill down’ in the spreadsheet. So I am looking for help getting this to work. I have tried many things shown here:

The basic for statement is:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>for row in range(8, finalrow + 1):
cell_value = f"=F{row-1} + C{row}"
print("cell formula", cell_value)
</code>
<code>for row in range(8, finalrow + 1): cell_value = f"=F{row-1} + C{row}" print("cell formula", cell_value) </code>
for row in range(8, finalrow + 1):
    cell_value = f"=F{row-1} + C{row}"
    print("cell formula", cell_value)

I have tried each of these things:

  1. worksheet2.cell(row=row, column=6,value=form_data[‘cell_value’]).font=red_font

  2. worksheet2.array_formulae[“F{row}”] = “=F{row-1} + C{row}”

  3. worksheet2.cell(row=row, column=6, value=”=F{row-1} + C{row}”).font = red_font

  4. worksheet2.cell(row=row, column=6, value=form_data[f”=F{row-1} + C{row}”]).font = red_font

  5. worksheet2[f”C{row}”] = Translator(“=B6/$F$3)”, origin=”c7″).translate_formula(f”C{row}”)
    Comment on 5) – I believe Translator is the command I want to use but I cannot understand how to use it in this case as a fill down. For this Translator line I received this error message File “C:C Drive DocumentsPete HomePython Excelbond-input.py”, line 292, in
    worksheet2[f”F{row}”] = Translator(“=C8+F7)”, origin=”F7″).translate_formula(f”F{row}”)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File “C:UserslarocAppDataLocalProgramsPythonPython312Libsite-packagesopenpyxlformulatranslate.py”, line 50, in init
    self.tokenizer = Tokenizer(formula)
    ^^^^^^^^^^^^^^^^^^
    File “C:UserslarocAppDataLocalProgramsPythonPython312Libsite-packagesopenpyxlformulatokenizer.py”, line 53, in init
    self._parse()
    File “C:UserslarocAppDataLocalProgramsPythonPython312Libsite-packagesopenpyxlformulatokenizer.py”, line 87, in _parse
    self.offset += dispatchercurr_char
    ^^^^^^^^^^^^^^^^^^^^^^^
    File “C:UserslarocAppDataLocalProgramsPythonPython312Libsite-packagesopenpyxlformulatokenizer.py”, line 246, in _parse_closer
    token = self.token_stack.pop().get_closer()
    ^^^^^^^^^^^^^^^^^^^^^^
    IndexError: pop from empty list

  6. I saw this solution using xlswrite package – but xlswriter cannot open up an existing .xlsx file to edit so I cannot use it.

worksheet2.write_formula(f”f{row}”, ‘cell_value’) # from xlxwriter

So any creative solution doing a ‘select’ and ‘fill down’ using openpyxl I would appreciate or any syntax corrections in my attempts would be useful.

BTW – I had no idea how to start with this so I had ChatGPT generate the code which is how I got started and that solution did not work.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật