I want to be able to access .xlsx files from Python 2.5.
Newest version of xlrd support .xlsx but not Python 2.5, and older versions of xlrd support Python 2.5 but not .xlsx.
I can't make openpyxl work. (See related question Install Openpyxl on python2.5 on Windows)
Finally I'm trying running Excel using win32, but it collides with existing instances of Excel open, it's a bit hackish.
Are there other alternatives?
There is one I know of : Pywin32. The latest version(build 219 from May 2014) is compatible all the way back to Python 2.3, you must just download the right version.
Now, the big trouble with Pywin32 is that it's badly documented and that without prior knowledge of COM/Visual Basic it's a pain to start rolling. Once you do and can just copy/paste macro code generated by excel it gets far easier.
This is what you want to do to get rolling :
import win32com.client
excel = win32com.client.Dispatch('Excel.Application')
If you then type, say excel.Workbooks.Add() you create a grand new excel workbook(you need to assign that to a variable to use it). So yeah, there is an alternative, but there is a learning curve involved.
PS :
You'll want to check out the Workbooks and Worksheets methods.
Related
I am brand new to FreeCAD and fairly new to python in general.
I have a project going on in which I have a list of several hundred (x,y) coordinates stored in two columns in an Excel doc. These points define a slice of an elevation profile. What I'm needing to do is draw a line/shape in FreeCAD using these points that can then be extruded into an extended version of this shape. Since the data is currently in excel, I'm leaning towards using pandas to access it, but I'm open to other ideas.
The problem I'm having with this line of thinking so far is that I can't figure out a way to access pandas from inside FreeCAD, so I've been attempting to use Winpython(2.7.10) through the Spyder ide to import FreeCAD(0.16) and pandas into the same script. I've tried adding both the Freecad/bin and Freecad/lib folders to my path (using this recommended method https://www.freecadweb.org/wiki/Embedding_FreeCAD/en), but have yet to have any success importing.
The error is: "DLL load failed: The specified procedure could not be found." .... Searching around, I can't seem to find FreeCad.dll or FreeCAD.so anywhere in my install, yet FreeCAD runs normally when used independently.
To summarize: Wanting to run FreeCAD through an external python console in order to access excel data through pandas (which doesn't seem to be available within FreeCAD itself). In doing so, I get an error and FreeCAD isn't accessible. It might be a version compatibility issue, or something more complex.
If you made it here, thank you for taking the time to read through my fairly complex/niche problem. Please feel free to suggest any more elegant alternatives, as I said, I'm new to this and likely haven't come across all possible solutions.
Thank you
I'm not exactly certain what "pandas" is - a quick search didn't reveal anything except the game engine Panda3D and the animal itself...
As for accessing data external to FreeCAD, this is something I've been exploring myself lately. At the moment, some success has been achieved by starting FreeCAD in server mode and having it watch an excel file, then running python script when it changes.
This approach would allow you to parse an Excel file using commonly available python libraries for that purpose.
EDIT:
Having been informed on just what pandas is, it seems odd you can't make it work with FreeCAD. However, there could be a number of causes:
Old version. FreeCAD is undergoing really significant change right now. Ensure you're using the latest stable release (0.17 - Roland), but I'd recommend getting your hands on the latest 0.18-dev release
Incorrect python version - FreeCAD currently is built on Py2, though Py3 builds are possible (I run FreeCAD / Py3 on my linux machine). Ensure you've installed pandas appropriately to match the python version FreeCAD depends upon (Py2, most likely).
Invalid install - If you know pandas imports and works in the python interpreter itself, try importing and running pandas code from the FreeCAD python console.
I want to run a python script from VBA using xlwings. I have installed the excel add-in by running
xlwings addin install
from the command prompt, however, the 'xlwings' reference is not showing up in the list of available references in my VBA project. (As a separate but perhaps connected issue, the xlwings add-in in the ribbon is only partly showing: it only shows the 'Active Workbook' and 'Advanced' subcategory.)
I am on Windows 7 Enterprise and Excel 2016
I came across the same problem. However, there was a work around. Since ultimately you want the work without alerting "no xlwings moduldes", you can manually import xlwings and xlwings_udfs modules into your current workbook then it will work. Those two modules should be available on any example spreadsheet from xlwings official website.
I just had the same issue. xlwings seems to be in the list, if you have "VBAProject (Book1)" selected before going to Tools->References.
You have to make sure that you do not have the "xlwings (xlwings.xlam)" module selected, before selecting Tools-> References.
Try removing the xlwings module from the VBA project(must be empty to remove...you should only have config settings there anyways) and installing the add-in via command line(xlwings addin install). Now when you try to edit your references, first confirm the xlwings project is visible in the VBA project directory on the left, and then select your current project and try to add a reference. Xlwings should now be in that list. I managed to resolve several issues by upgrading to the latest xlwings version - the older version Anaconda came with seemed to be missing a fair amount of functionality, mainly concerning the add-in(which as far as I can tell is superior to the module.)
Is there any existing Python library that can validate data in Excel format? Or what kind of keyword should I use to search such an open source project? Thanks.
[Disclosure: I'm the author of xlrd]
xlrd allows you to extract data from XLS files. XLSX support is in alpha testing; e-mail me if you need it. You get told precisely what is in each cell (Excel cell type and value). It runs on Python 2.1 to 2.7 on any platform. You don't need Windows. You don't need Excel to be installed on your machine. Start with the tutorial found here.
I`m not sure what are you looking for, but there are three libraries that, in combination, can read and write excel files:
xlrd
xlwt
xlutils
They read and save binary excel archives both in windows and linux. There are functions for formatting data and styles.
If you want to check if some data column is in a given format you can do it with these libs (basically with xlrd).
I have some data in CSV format that I want to pull into an Excel spreadsheet and then create some standard set of graphs for. Since the data is originally generated in a Python app, I was hoping to simply extend the app so that it could do all the post processing and I wouldn't have to do it by hand. Is there an easy interface with Python to work with and manipulate Excel spreadsheets? Any good samples of doing this? Is this Windows only (I'm primarily working on a Mac and have Excel, but could do this on Windows if necessary).
xlutils (and the included packages xlrd and xlwt) should allow your Python program to handily do any creation, reading and manipulation of Excel files you might want!
On Windows you could use the pywin32 package to create an Excel COM Object and then manipulate it from a script. You need to have an installed Excel on that machine though. I haven't done this myself so I can't give you and details but I've seen this working so can at least confirm that it's possible. No idea about OS X, unfortunately.
how would you parse a Microsoft OLE compound document using Python?
Edit: Sorry, I forgot to say that I need write support too.. In short, I have an OLE compound file that I have to read, modify a bit and write back to disk (it's a file made with a CAD application)
Just found OleFileIO_PL, but it doesn't have write support.. :/ and as of version 0.40 (2014) it has write support.
Edit: Looks like there's a way (though Windows-only) that supports writing too.. The pywin32 extensions (StgOpenStorage function and related)
An alternative: The xlrd package has a reader. The xlwt package (a fork of pyExcelerator) has a writer. They handle filesizes of 100s of MB cheerfully; the packages have been widely used for about 4 years. The compound document modules are targetted at getting "Workbook" streams into and out of Excel .xls files as efficiently as possible, but are reasonably general-purpose. Unlike OleFileIO_PL, they don't provide access to the internals of Property streams.
http://pypi.python.org/pypi/xlrd
http://pypi.python.org/pypi/xlwt
If you decide to use them and need help, ask in this forum:
http://groups.google.com/group/python-excel
For completeness: on Linux there's also the GNOME Structured File Library (but the default package for Debian/Ubuntu has Python support disabled, since the Python bindings are unsupported since 2006) and the POIFS Java library.