简体   繁体   English

xlrd,xlwt,xlutils如何在低级使用Excel?

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

They are all open source Python packages to control Excel (see python-excel ). 它们都是用于控制Excel的开源Python软件包(请参阅python-excel )。 I am still trying to understand their code. 我仍在尝试了解他们的代码。 If anyone could give a hint, do how they connect in a low lever to Excel? 如果有人可以提供提示,他们如何以低杠杆的方式连接到Excel? Via xml, Excel API, or some other basic Python packages? 通过xml,Excel API或其他一些基本的Python包?

If we are talking about reading and writing XLS files, basically xlrd and xlwt follow the OpenOffice.org document/specification describing Excel's format and BIFF (Binary Interchange File Format) records to read and write XLS files. 如果我们正在谈论读写XLS文件,则基本上xlrdxlwt遵循描述Office Excel格式和BIFF (二进制交换文件格式)记录的OpenOffice.org文档/规范来读取和写入XLS文件。 If you would inspect the xlwt source code , you would find it manipulates the BIFF records for everything needs to be written: creating workbook, worksheets, writing data, formatting, alignment etc. 如果您检查xlwt源代码 ,则会发现它可以操纵BIFF记录来满足需要编写的所有内容:创建工作簿,工作表,编写数据,格式化,对齐等。

With XLSX the story is a bit different. 使用XLSX时 ,情况有所不同。 To read XLSX xlrd relies on the openxmlformats XML schemas and use built into Python ElementTree XML parsers ( cElementTree if available, otherwise ElementTree ) to parse the XLSX file which is, to simplify, a zip archive containing XML files inside. 要读取XLSX, xlrd依赖于openxmlformats XML模式,使用内置于Python的ElementTree XML解析器 (如果可用, cElementTree ,否则使用ElementTree )来解析XLSX文件,为简化起见,该文件是内部包含XML文件的zip存档。 Here is a good overview of what is inside the archive: 以下是档案库内容的良好概述:

I would also recommend studying the xlsxwriter module - from my point of view, the package is much better documented and the code is much more cleaner and readable than xlwt or xlrd . 我还建议研究xlsxwriter模块 -从我的角度来看,该软件包的文档记录要好得多, 并且代码xlwtxlrd更清晰易读。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM