简体   繁体   中英

Running Python on Microsoft Visual Studio to edit .xlsx files into CSV, is it possible with Openpyxl?

I use Microsoft Visual Studio as my IDE.

I want to write some python that will take a Microsoft Excel file (.xlsx) and perform some functions with another different CSV file.

From my understanding python cannot work with .xlsx unless you have a module like "xlrd" or "openpyxl"

If I install either one of these modules, will Microsoft Visual Studio also be able to manipulate .xlsx files? Or will I only be able to manipulate .xlsx files within the Python IDLE IDE.

How can I make Microsoft Visual Studio able to run Python that can also handle .xlsx? Or should I give up on Microsoft Visual Studio completely and move to something else?

Yes, Visual Studio will be able to manipulate .xlsx files, as long as it uses a version of Python that has access to the openpyxl or xlrd modules.

When you install openpyxl or xlrd, either for Python 2 or Python 3 (presumably you use pip or conda to do this), those modules will be installed to a site-packages directory. When you create a Python program that contains an import openpyxl or import xlrd , when Python reaches those lines it will look in that site-packages directory for the requisite module. If Python finds the module, everything is fine, and you now have access to the full functionality of that module, which will allow you to do your thing.

The IDE is not the underlying Python engine itself, it's just a wrapper. Visual Studio, PyCharm, Eclipse, and IDLE are just programs that wrap a Python executable (also called the Python interpreter). The only thing you have to make sure of is, when you install the module (using, for example, pip install openpyxl ), that pip should be associated with the same Python executable that your IDE uses.

You can check what Python interpreter your Visual Studio is using (somewhere in the preferences?). It should also list the version of Python and the location of the site-packages directory. If you run pip from your command line with the -V flag you'll see something like this (varies depending on how you installed Python):

C:\> pip -V
pip 9.0.1 from C:\anaconda3\lib\site-packages (python 3.5)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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