Is Python better than Excel

[Python-de] VBA or Python (via win32com or similar) better for Excel file operations?

Massa, Harald Arminchef at
Fri Jan 4 13:30:21 CET 2013
Hello! > I would have to do a lot with Excel files in the near future. There would be > Offer VBA if you are close to MS and Windows. More is being discussed on the python-excel mailing list, there are more people who can help! > 1) Python via module win32com (does that work with Python 3.3?) > 2) Python modules xlrd, xswt from > 3) VBA. Pretty good summation. EXCEPT: -> the control of Excel via COM (is definitely still available under several marketing terms) is possible from any language that COM can control. Python is just one of them. In addition, there are modules for C # / as .net module libraries to write .xltx and so on. The reports on this sounded exhausting, which is why I have prioritized the attempts to implement this with pythondotnet to "sometime" again. Advantages and disadvantages of the methods: 1.) Control via COM. Most of the Excel functionality can be accessed via this. The procedure is: start an Excel program-controlled, give commands to Excel via a program-to-program interface. Consequence: Excel must be available. In various Microsoft documentation you can also find information that Microsoft Excel is made for interactive use; there is no guarantee or support for the program-controlled use (to what extent it is allowed, ask three lawyers for 6 opinions) Advantage: almost everything is possible. Disadvantage: When Excel blocks, it blocks. (e.g. "press a key because the link to ZZZ is not tangible") The feedback when something is not possible (too long character string entered in cell; wrong coding, object does not exist) are ... only sometimes understandable; often generic mistakes. 2.) Control via XLRD / XLWT. The Excel format is parsed and the Excel format is also written. For lists, this is perfect and really fast. Formatting is possible to a limited extent. Topics such as pivots, auto filters, hiding columns, and automatic column width are sometimes not possible, sometimes really exhausting. Macro calls do not work at all. Advantages: no Excel required, extremely fast. Disadvantages: Limited functionality. Currently only available for .xls; xltx in announcements 3.) Control via VBA. A little more is possible with this than with COM - some elements of the object model cannot be grasped via COM or only so incorrectly that it makes no sense. Advantage: part of Excel. Largest range of functions Disadvantages: Less elegant language (compared to Python). Macros saved in Excel workbooks, e.g. version management only possible with difficulty; Corrupted Excel folders sometimes take macros with them in the Orcus. My experience: a) if xlrd / xlwt are enough for the problem, work with it. Especially for reading and writing lists that would actually be better off as .csv, they are super good. A bold headline is also possible. b) if design and graphics are required, create templates in Excel, open via COM and fill in via COM. Data generation in Python. I have had experience with b) since 2000, with a) for around 5 years. I've burned my fingers with VBA programming. Best regards Harald - GHUM GmbH Harald Armin Massa Spielberger Strasse 49 70435 Stuttgart 0173/9409607 District Court Stuttgart, HRB 734971

More information on the python-de mailing list