Differences between xlwings vs openpyxl Reading Excel Workbooks

前端 未结 1 910
轻奢々
轻奢々 2021-01-02 06:26

I\'ve mostly only used xlwings to open (read-write) workbooks (since the workbooks I read have complicated macros). But I\'ve recently begun using openpyxl to o

相关标签:
1条回答
  • 2021-01-02 07:04

    You are correct in that xlwings relies on pywin32, whereas openpyxl does not.

    openpyxl

    A ".xlsx" excel file is essentially a zip-file containing multiple XML files formatted according to Microsoft's OOXML specification. With this specification it's possible to create a program capable of directly reading/writing excel files in just about any programming language. This is the approach applied in openpyxl: it uses python code to read/write excel files directly.

    xlwings

    A Microsoft Excel application can be started and controlled by an external program through the Win32 COM API. The pywin32 package provides an interface between Win32 COM and Python. Through a python script with the right pywin32 commands you can fully control an Excel Application (open excel files, query data from cells, write data to cells, save excel files, etc.). The pywin32 commands that you can use mirror the Excel VBA commands, albeit with python syntax.

    xlwings is (among other things) a user-friendly wrapper around pywin32. It introduces several concise-yet-powerful methods. An example would be the methods for direct conversion of an excel cell range to a numpy array or pandas dataframe (and vice versa).

    Summary

    A fundamental difference between xlwings and openpyxl is that the former requires that MS Excel is installed on your machine, whereas the latter does not.

    0 讨论(0)
提交回复
热议问题