xlwings,jupyter笔记本和Excel

问题描述 投票:0回答:1

我是xlwings的忠实拥护者,通常使用它来将数据从jupyter发送到Excel。我想以另一种方式使用运行主加载项(v。0.18)(不使用任何vba或宏)来从Excel中运行jupyter笔记本。我设法使用quickstart myproject运行普通的.py文件,没有任何问题。是否可以运行.ipynb文件而不是.py文件,如果可以,如何运行?

非常感谢您的帮助

汤姆

python excel jupyter-notebook xlwings
1个回答
0
投票

您需要从main()函数中调用Jupyter API。像这样的东西:

import nbformat
from nbconvert.preprocessors import ExecutePreprocessor

def main():
    with open(notebook_filename) as f:
        nb = nbformat.read(f, as_version=4)
    ep = ExecutePreprocessor(timeout=600, kernel_name='python3')
    ep.preprocess(nb, {'metadata': {'path': 'notebooks/'}})
    with open('executed_notebook.ipynb', 'w', encoding='utf-8') as f:
        nbformat.write(nb, f)

请参见Jupyter docs

© www.soinside.com 2019 - 2024. All rights reserved.