Wondering if Python has free and reliable library to read Excel file, manipulate data and generate Excel file output, just like VBA did? My current problem is, the project has both Python and VBA code, I am trying to see if I can use single programming language to make it simple. Thanks.
想知道Python是否有免费可靠的库来读取Excel文件,操作数据并生成Excel文件输出,就像VBA一样?我目前的问题是,该项目同时包含Python和VBA代码,我试图看看我是否可以使用单一编程语言来简化它。谢谢。
Using Python 2.7.
使用Python 2.7。
regards, Lin
2 个解决方案
#1
1
I would like to recommend openpyxl
我想推荐openpyxl
I used it for creating basic Excel reports for business teams, and it has been a pleasure to use. :-)
我用它来为业务团队创建基本的Excel报告,并且很高兴使用它。 :-)
#2
2
I either use openpyxl or the pywin32 COM interface directly. openpyxl is very fast as it manipulates data directly in the excel file on disk, where as the pywin32 com interface uses Excel itself, with the python code mimicking what VBA does.
我直接使用openpyxl或pywin32 COM接口。 openpyxl非常快,因为它直接在磁盘上的excel文件中操作数据,其中pywin32 com接口使用Excel本身,python代码模仿VBA所做的事情。
The main difference between the two is that openpxl only gives you a subset of commands, so great for pulling data out of an excel file to use elsewhere or building a new excel file from existing data. However to get the full functionality you need to use the COM interface.
两者之间的主要区别在于openpxl只为您提供了一个命令子集,非常适合从excel文件中提取数据以在其他地方使用或从现有数据构建新的Excel文件。但是,要获得使用COM接口所需的全部功能。
This site gives a good intro to using the COM interface. One thing to watch out for is the constants that are scattered throughout the COM interface calls. You generally need to find out those values yourself, you can start by looking here
该站点为使用COM接口提供了很好的介绍。需要注意的是散布在COM接口调用中的常量。您通常需要自己找出这些值,您可以从这里开始
Finally you can also take a look at IronPython which is a .NET implementation of python which gives a cleaner interface but isn't actually vanilla python (and not cross-platform), so maybe not what you want.
最后你还可以看一下IronPython,这是一个python的.NET实现,它提供了一个更干净的界面,但实际上并不是vanilla python(而不是跨平台),所以也许不是你想要的。
#1
1
I would like to recommend openpyxl
我想推荐openpyxl
I used it for creating basic Excel reports for business teams, and it has been a pleasure to use. :-)
我用它来为业务团队创建基本的Excel报告,并且很高兴使用它。 :-)
#2
2
I either use openpyxl or the pywin32 COM interface directly. openpyxl is very fast as it manipulates data directly in the excel file on disk, where as the pywin32 com interface uses Excel itself, with the python code mimicking what VBA does.
我直接使用openpyxl或pywin32 COM接口。 openpyxl非常快,因为它直接在磁盘上的excel文件中操作数据,其中pywin32 com接口使用Excel本身,python代码模仿VBA所做的事情。
The main difference between the two is that openpxl only gives you a subset of commands, so great for pulling data out of an excel file to use elsewhere or building a new excel file from existing data. However to get the full functionality you need to use the COM interface.
两者之间的主要区别在于openpxl只为您提供了一个命令子集,非常适合从excel文件中提取数据以在其他地方使用或从现有数据构建新的Excel文件。但是,要获得使用COM接口所需的全部功能。
This site gives a good intro to using the COM interface. One thing to watch out for is the constants that are scattered throughout the COM interface calls. You generally need to find out those values yourself, you can start by looking here
该站点为使用COM接口提供了很好的介绍。需要注意的是散布在COM接口调用中的常量。您通常需要自己找出这些值,您可以从这里开始
Finally you can also take a look at IronPython which is a .NET implementation of python which gives a cleaner interface but isn't actually vanilla python (and not cross-platform), so maybe not what you want.
最后你还可以看一下IronPython,这是一个python的.NET实现,它提供了一个更干净的界面,但实际上并不是vanilla python(而不是跨平台),所以也许不是你想要的。