![]() |
openpyxl insert list with formulas - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: openpyxl insert list with formulas (/thread-34924.html) |
openpyxl insert list with formulas - Irv1n - Sep-15-2021 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 RE: openpyxl insert list with formulas - Irv1n - Sep-16-2021 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? |