我在康达完成了Pycel的pip安装
我在Jupyter笔记本中执行此操作
%matplotlib inline
from pycel import ExcelCompiler
from IPython.display import FileLink
import matplotlib.pyplot as plt
filename = "../python/pycel_files/example.xlsx"
print("Loading {}...".format(filename))
# load & compile the file to a graph
excel = ExcelCompiler(filename=filename)
# test evaluation
print("B1 is {}".format(excel.evaluate('Sheet1!B1')))
print("B2=(B1+5) is {}".format(excel.evaluate('Sheet1!B2')))
产出:如预期
B1 is 10
B2=(B1+5) is 15
但是,如果我现在这样做:
print("Setting B1 to 200")
excel.set_value('Sheet1!B1', 200)
print("B2 is now %s (the same should happen in Excel)" % excel.evaluate(
'Sheet1!B2'))
我得到了Jupyter中的预期输出:
Setting B1 to 200
B2 is now 205 (the same should happen in Excel)
问题:
所以这里有一个误解,关于Pycel是什么,做什么。从Pycel Readme开始:
因此,要回答您的问题:
Pycel不会更改Excel文件。它从excel文件中读取数据,并从所需的单元格中创建“已编译”的电子表格
您可能需要重新编译excel电子表格,以便在Python代码中显示任何结果
Pycel确实处理床单。它与细胞一起工作。这些单元格可以来自工作簿中的任何工作表
相关问题 更多 >
编程相关推荐