Python Forum
openpyxl insert list with formulas
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
openpyxl insert list with formulas
#1
Hello
I have this code:
wb = Workbook()
ws = wb.active
listf = [[1,1,1,1], [2,2,2,2], [3,3,3,3]]
calc_lst = [['=СЧЁТЕСЛИ(listf[x];"<>")'], ["=СРЗНАЧ(listf[x]"], ["=СТАНДОТКЛОН(listf[x])"], ['=СТАНДОТКЛОН(listf[x])/корень(СЧЁТЕСЛИ(listf[x];"<>"))']]
def col_writer(row_number, column_number, lst):
    for col in range(len(lst)):
        for row in range(len(lst[col])):
            ws.cell(row+row_number, col+column_number, lst[col][row])
    return wb.save("sample.xlsx")
col_writer(1,2, listf)
and i need to insert: calc_lst in this file too under list: listf

Like this:
[/img]screenshot
Reply
#2
Okey i rewrite my code and its work:
wb = Workbook()
ws = wb.active
listf = [[1,1,1,1], [2,2,2,2], [3,3,3,3]]


def col_writer(row_number, column_number, lst):
    for c_index, col in enumerate(lst, start=4):
        for r_index, row in enumerate(col, start=6):
            ws.cell(r_index, c_index, row)
        c = get_column_letter(c_index)  # column letter
        calc_lst = [f'=СРЗНАЧ({c}6:{c}35)', f'=СРЗНАЧ({c}6:{c}35)', f'=СТАНДОТКЛОН({c}6:{c}35)', f'=СТАНДОТКЛОН({c}6:{c}35)']
        for r_index, formula in enumerate(calc_lst, start=37):
            ws.cell(r_index, c_index, formula).number_format = numbers.FORMAT_GENERAL
    return wb.save('sample.xlsx')


col_writer(1,1,listf)
But my formulas work only if i open this xlsx file and double click to cell with formula, maybeanyone know how to fix it?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Updating formulas in Excel - best solution MasterOfDestr 4 650 Mar-11-2024, 01:02 PM
Last Post: MasterOfDestr
  plotting based on the results of mathematical formulas Timur 1 332 Feb-08-2024, 07:22 PM
Last Post: Gribouillis
  openpyxl insert picture problem cools0607 2 1,515 May-03-2023, 06:48 AM
Last Post: cools0607
  store all variable values into list and insert to sql_summary table mg24 3 1,128 Sep-28-2022, 09:13 AM
Last Post: Larz60+
  Help with a query - to show possible formulas Yanos 1 1,760 Nov-02-2020, 12:18 AM
Last Post: jefsummers
  How to ignore formulas when reading excel file SriMekala 3 6,499 Aug-16-2019, 04:04 PM
Last Post: buran
  python 3 math formulas where to use () Python101 1 2,297 Jun-09-2019, 09:54 PM
Last Post: micseydel
  how to insert list into database zubair 2 9,916 Feb-05-2019, 12:16 PM
Last Post: rajesh1997
  Insert list in particular column! Help! vndywarhol 0 2,474 Sep-17-2018, 11:14 PM
Last Post: vndywarhol
  insert list into sqlite3 mepyyeti 3 13,679 Jan-15-2018, 06:35 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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