使用 PyXLL 将 Jupyter 笔记本添加到 Microsoft Excel。
项目描述
PyXLL-Jupyter
Jupyter 笔记本和 Microsoft Excel 的集成。
有关更多详细信息,请参阅Excel博客文章中的Python Jupyter Notebooks 。
要求
- PyXLL >= 5.1.0
- Jupyter >= 1.0.0
- 笔记本 >= 6.0.0
- PySide2 或 Python 的 PySide6 >= 3.10
可选的
- jupyterlab >= 4.0.0
安装
要安装此软件包,请使用:
pip install pyxll-jupyter
安装后,只要您已经安装了 PyXLL 5 或更高版本,就会将“Jupyter Notebook”按钮添加到 Excel 的 PyXLL 功能区选项卡中。
在 Excel 中使用 Jupyter 时,Python 内核使用 PyXLL 在 Excel 进程中运行。您可以通过 Jupyter notebook 中的代码与 Excel 交互,并使用 PyXLL 装饰器 @xl_menu 和 @xl_macro 等编写 Excel 函数。
由于内核在 Excel 进程中的现有 Python 解释器中运行,因此无法重新启动内核或使用其他 Python 版本或其他语言。
配置
要配置,请将以下内容添加到您的 pyxll.cfg 文件(显示默认值):
[JUPYTER]
use_workbook_dir = 0
notebook_dir = Documents
subcommand = notebook
timeout = 30
qt = PySide2
disable_ribbon = 0
如果设置了use_workbook_dir并保存了当前工作簿,那么 Jupyter 将在与当前工作簿相同的文件夹中打开。
subcommand选项可用于切换用于启动 Jupyter Web 服务器的 Jupyter 子命令。它可以设置notebook为默认的 Jupyter notebook 界面,或者lab如果使用 Jupyterlab
(experimental)。
如果设置了disable_ribbon,则不会显示启动 Jupyter 的功能区按钮,但仍可以使用“OpenJupyterNotebook”宏打开 Jupyter。
实验性 JupyterLab 支持
subcommand = lab通过在 pyxll.cfg 文件的[JUPYTER]部分中指定,可以使用 Jupyterlab 代替默认的 Jupyter Notebook 界面
。
这需要安装 Jupyterlab >= 4.0.0。在撰写本文时,Jupyterlab 的第 4 版处于预发布状态,可以使用以下方式安装:
pip install --pre jupyterlab
Qt
pyxll-jupyter 包使用 Qt QWebEngineView小部件,默认情况下将使用Python <= 3.9 的 PySide2 包或Python >= 3.10的PySide6包。
通过在配置部分中进行设置,可以将其更改为使用PyQt5 。如果使用此选项,您将需要安装和包。两者都可以使用 pip 安装,如下所示:qt = PyQt5JUPYTERpyqt5pyqtwebengine
pip install pyqt5 pyqtwebengine
魔术函数
除了标准的 Jupyter 魔术函数之外,还提供以下魔术函数:
%xl_get [-c CELL] [-t TYPE] [-x]
Get the current selection in Excel into Python.
optional arguments:
-c CELL, --cell CELL Address of cell to get value of.
-t TYPE, --type TYPE Datatype to convert the value to.
-x, --no-auto-resize Don't auto-resize the range.
%xl_set [-c CELL] [-t TYPE] [-f FORMATTER] [-x] value
Set a value to the current selection in Excel.
positional arguments:
value Value to set in Excel.
optional arguments:
-c CELL, --cell CELL Address of cell to get value of.
-t TYPE, --type TYPE Datatype to convert the value to.
-f FORMATTER, --formatter FORMATTER
PyXLL Formatter to use when setting the value.
-x, --no-auto-resize Don't auto-resize the range.
%xl_plot [-n NAME] [-c CELL] [-w WIDTH] [-h HEIGHT] figure
Plot a figure to Excel in the same way as pyxll.plot.
The figure is exported as an image and inserted into Excel as a Picture object.
If the --name argument is used and the picture already exists then it will not
be resized or moved.
positional arguments:
figure Figure to plot.
optional arguments:
-n NAME, --name NAME Name of the picture object in Excel to use.
-c CELL, --cell CELL Address of cell to use when creating the Picture in
Excel.
-w WIDTH, --width WIDTH
Width in points to use when creating the Picture in
Excel.
-h HEIGHT, --height HEIGHT
Height in points to use when creating the Picture in
Excel.
有关安装和使用 PyXLL 的更多信息,请参阅https://www.pyxll.com。
版权所有 (c) PyXLL Ltd
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。
内置分布
pyxll_jupyter -0.3.1-py3-none-any.whl 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | f08f0da46d054386ca0ca9e0ef5bab00c51b3a65d91fedcf79fd04f7c21511e8 |
|
| MD5 | 984a4bf6378dbd3f6f90c19203628917 |
|
| 布莱克2-256 | a0b20375b59560cf86576804ebf009268d504f3ee2c05733e9351aa0524b6e25 |