简体   繁体   English

在整列python中插入一个excel公式

[英]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. 我正在开发一个项目,我想在现有工作簿表的特定列中插入excel公式。

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) 我需要在特定单元格的excel文件中显示公式(例如,如果有人点击单元格A1并且有一个公式(V查找)它应该显示该公式)

I tried with xlsxwritter but I am not getting them the accurate result. 我尝试使用xlsxwritter但我没有得到准确的结果。

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")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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