简体   繁体   中英

insert a excel formula in whole column python

I m working on some project where I want to insert an excel formula in a particular column in an existing workbook sheet.

I need to show the formula in the excel file of a particular cell (for example if someone clicks on cell A1 and there is a formula of (V lookup) it should show that formula)

I tried with xlsxwritter but I am not getting them the accurate result.

Any piece of code or any approach on this

This would work:

    import openpyxl 
    i=1
    wb = openpyxl.Workbook() 
    sheet = wb.active
    for i, cellObj in enumerate(Sheet['D'], 1): #assuming you will need to 
         cellObj.value = '=IF(OR(B2 ="rj", B2 ="rj1", B2 ="rj2"),rj)'

    wb.save("yourfile.xlsx")

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