简体   繁体   中英

Unable to refernce a cell into an excel formula using openpyxl

from openpyxl import Workbook

wb = Workbook()
ws = wb.create_sheet("Summary")

ws.cell(5,8).value = f'=PERCENTILE({ws.min_row}:{ws.max_row}, {ws.cell(6,6)}) 

So i want the formula to be dynamic. dynamic in the sense that the value results from this formula should change when the cell(6,6) value is changed just like it happen in excel but here in this case the cell is set with "=PERCENTILE(B2:B42, <Cell 'Summary'.F6>)" where it's just a string.

You've passed the object wherein what you need is the coordinate (cell reference).

ws.cell(5,8).value = f'=PERCENTILE({ws.min_row}:{ws.max_row}, {ws.cell(6,6).coordinate})'

ws.cell has an attribute "coordinate".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM