Skip to Content
Python for Excel (Chinese Edition), 2nd Edition
book

Python for Excel (Chinese Edition), 2nd Edition

by Felix Zumstein
May 2026
Intermediate
418 pages
5h 50m
Chinese
O'Reilly Media, Inc.
Content preview from Python for Excel (Chinese Edition), 2nd Edition

第 12 章. 使用 xlwings Lite编写脚本

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

像我们在第四部分构建的那样分发的xlwings工具是一项巨大挑战,因为它们要求在每个最终用户的计算机上安装Python及必要的包。xlwings Lite通过在现代Excel加载项内部运行Python,而不是依赖本地安装,从而解决了这一挑战。用户只需从Excel的加载项商店安装xlwings Lite,即可完成所有准备工作。

xlwings Lite的设计目标是让其操作体验尽可能接近VBA,无论对开发者还是最终用户皆是如此。与VBA类似,xlwings Lite将Python代码直接存储在工作簿中,因此最终用户只需安装xlwings Lite加载项即可。 作为开发者,您会感到非常熟悉:代码编辑器的操作体验与 VBA 编辑器相似——您甚至可以使用 F5 键运行代码。

要运行 xlwings Lite,您至少需要 Office 2021(永久许可证)或随 Microsoft 365 订阅附带的 Excel 安装版本。不过,即使您使用的是较旧版本的 Excel,也可以通过 Excel 网页版完成本章的示例操作。 更棒的是,它也兼容免费版 Excel——只需 注册一个免费的 Microsoft 账户,即可安装 xlwings Lite。

本章首先将介绍 xlwings Lite 的工作原理,随后引导您完成安装。在快速了解该加载项之后,我们将分析纽约市出租车数据集。在此过程中,我们将接触到一些令人兴奋的现代技术,包括 DuckDB、Parquet 文件以及 Python 的 Asyncio 库。最后,我们将通过探讨 xlwings Lite 的特殊性和局限性来结束本章。

xlwings Lite 入门

在本节中,我将简要概述 xlwings Lite 的工作原理,随后引导您完成该插件的安装。之后,您将运行在 xlwings Lite 中的第一个脚本——既可以通过 xlwings Lite 用户界面运行,也可以通过工作表上的按钮运行。

xlwings Lite 的工作原理

xlwings Lite( )是一款现代 Office.js 加载项,由基于 WebAssembly(Wasm)的 Python 发行版Pyodide 提供支持。这听起来有些晦涩难懂,让我们来看看这究竟意味着什么!

多年来,微软推出了多种用于构建 Excel 加载项的技术:包括 VBA(Visual Basic for Applications)、VSTO(Visual Studio Tools for Office)、COM(组件对象模型)以及 XLL(Excel 专用动态链接库)加载项。 尽管技术各异,但它们有一个共同点:均不支持基于网页或移动设备的 Excel,因此 微软不得不推出另一项名为Office.js的新技术——该技术以当前形式随 Office 2016 一起发布。 Office.js 是一个 JavaScript 库,支持创建可在浏览器中运行的跨平台加载项。这意味着加载项的源文件必须托管在服务器或 Cloud 端。 浏览器是一个沙箱环境,默认情况下无法访问计算机上的任何内容,这使得 Office.js 加载项比 VBA 安全得多。唯一的主要安全隐患在于,恶意加载项可能篡改您正在使用的工作簿并发送其内容。就像智能手机应用一样,Office.js 加载项可以发布在 Office 加载项商店中,您只需单击一下即可安装。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

学习勒索软件响应和恢复 (Chinese Edition)

学习勒索软件响应和恢复 (Chinese Edition)

W. Curtis Preston, Michael Saylor
Prometheus:快速入门,第二版

Prometheus:快速入门,第二版

Julien Pivotto, Brian Brazil

Publisher Resources

ISBN: 0642572396008