Excel在Openpyxl生成的工作簿中添加@符号 [英] Excel adding @ signs in Openpyxl generated workbooks

查看:73
本文介绍了Excel在Openpyxl生成的工作簿中添加@符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试编写python脚本,以从json文件生成excel工作簿模板文件.为此,我一直在使用openpyxl并在模板中实现excel函数,以便于访问.我不太精通excel,并且我将python用作学习的催化剂".打开生成的文件时,我发现输入的函数在某些位置带有"@"符号.

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.

在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函数来自: https://excelx.com/formula/if-cell-contains-text/#bm4 )

在excel中:
= @ IF(ISERR(VLOOKUP(F1,A1:B21,2,FALSE)),"False :(不)包含","True:已找到文本")

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

我相信这是在excel方面,因为当我在python中打印单元格时,我将得到与输入相同的字符串.

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)

我想知道是否有人有使用openpyxl的经验,以阐明如何解决此问题.

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

推荐答案

按照以下答案:

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

其中"t"代表类型,"ref"是要在其中写入公式的单元格数组.但是,我找不到与以下内容有关的任何资源:

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

这篇关于Excel在Openpyxl生成的工作簿中添加@符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆