Excel adding @ signs in Openpyxl generated workbooks

人盡茶涼 提交于 2021-02-11 13:01:44

问题


I am currently trying to write a python script to generate a excel workbook template file from a json file. To do this I have been using openpyxl and implementing excel functions in the template for ease of access. I'm not well-versed in excel, and I am using python as a "catalyst of learning." What I'm discovering when I open a generated file is that the functions I input have '@' symbols in certain places.

In python:

from openpyxl import Workbook
wb = Workbook()
sh = wb.active
sh["A2"] = "=IF(ISERR(VLOOKUP(F1,A1:B21,2,FALSE)),”False:Not Contains”,”True: Text Found”)"

(excel function from: https://excelx.com/formula/if-cell-contains-text/#bm4)

In excel:
=@IF(ISERR(VLOOKUP(F1,A1:B21,2,FALSE)),”False:(Not) Contains”,”True: Text Found”)

I believe that this is on the excel side, as when I print the cell in python, I will get the same string that I input.

print(sh["A2"].value)

I was wondering if anyone has had experience with openpyxl to shed some light on how to go about fixing this issue.


回答1:


Following the answer in: How to insert array formula in an Excel sheet with openpyxl? (thank you JvdV)

from openpyxl import Workbook
wb = Workbook()
sh = wb.active
sh["A2"] = '=IF(ISERR(VLOOKUP(F1,A1:B21,2,FALSE)),”False:Not Contains”,”True: Text Found”)'
sh.formula_attributes["A2"] = {"t": "array", "ref": "A2:A2"}

Where 't' represents type, and 'ref' is the array of cells to write the formula onto. However, I was not able to find any resources related to:

openpyxl.worksheet.worksheet.Worksheet.formula_attributes


来源:https://stackoverflow.com/questions/64827312/excel-adding-signs-in-openpyxl-generated-workbooks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!