xlrd、xlwt、xlutils如何在底层与Excel协同工作?

How do xlrd, xlwt, xlutils work with Excel in the low level?

它们都是开源 Python 包来控制 Excel(参见 python-excel)。我仍在努力理解他们的代码。如果有人能给出提示,他们如何以低杠杆连接到 Excel?通过 xml、Excel API 或其他一些基本的 Python 软件包?

如果我们谈论的是读取和写入 XLS 文件,基本上 xlrdxlwt 遵循 OpenOffice.org document/specification describing Excel's format and BIFF (Binary Interchange File Format) records to read and write XLS files. If you would inspect the xlwt source code,您会发现它操纵 BIFF 记录以获取所有需要写入的内容: 创建工作簿、工作表、写入数据、格式化、对齐等

使用 XLSX the story is a bit different. To read XLSX xlrd relies on the openxmlformats XML schemas and use built into Python ElementTree XML parserscElementTree 如果可用,否则 ElementTree)解析 XLSX 文件,为了简化,它是一个包含 XML 文件的 zip 存档。这是对存档内容的一个很好的概述:

我还建议研究 xlsxwriter module - from my point of view, the package is much better documented and the codexlwtxlrd.

更清晰和可读