Python Pycel问题

2024-05-14 16:09:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我在康达完成了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)

问题:

  1. 但是,在excel中,单元格B1不会更新。也就是说,它没有Pycel设定的值200。它仍然显示10
  2. 我在他们的示例github .ipynb of Pycel文件中遇到了同样的问题。有人能确认他们是否也面临同样的问题吗&;这看起来像个虫子
  3. 另外,如果我对他们的example excel file&;使用其.ipynb文件,matplotlib图形中不会显示任何内容。Pycel如何知道选择哪张纸?它是否始终默认为sheet1

Tags: thetoimportformatmatplotlibisjupyterfilename
1条回答
网友
1楼 · 发布于 2024-05-14 16:09:24

所以这里有一个误解,关于Pycel是什么,做什么。从Pycel Readme开始:

Pycel is a small python library that can translate an Excel spreadsheet into executable python code which can be run independently of Excel. The python code is based on a graph and uses caching & lazy evaluation to ensure (relatively) fast execution.

因此,要回答您的问题:

However in excel, cell B1 is not updated.

Pycel不会更改Excel文件。它从excel文件中读取数据,并从所需的单元格中创建“已编译”的电子表格

If I make any changes to their example excel file & use their .ipynb file nothing shows up in matplotlib graphs.

您可能需要重新编译excel电子表格,以便在Python代码中显示任何结果

How does the Pycel know which sheet to choose from? Does it default to sheet1 always?

Pycel确实处理床单。它与细胞一起工作。这些单元格可以来自工作簿中的任何工作表

相关问题 更多 >

    热门问题