Import Excel Data on rhino python

Hi, I’m trying to import xlrd on rhino python but I can’t manage to do it. I don’t find a solution for this case on internet so I was wondering if one of you can help me.

Thanks !

Does this help?

http://www.ironpython.info/index.php?title=Interacting_with_Excel

– Dale

I’m working on it but it doesn’t work. When I’m writing “import xlrd”, it says that there is no xlrd module. I’m trying to install it but PIP doesn’t work and I don’t know where I can put the files that I’ve downloaded.

Hi @maelig.gaborieau

If you follow the instructions in the link Dale posted above you’ll notice that you won’t use xlrd module at all - the only module you import is the clr module.

import clr
clr.AddReferenceByName('Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c')
from Microsoft.Office.Interop import Excel

ex = Excel.ApplicationClass()   
ex.Visible = True
ex.DisplayAlerts = False   

workbook = ex.Workbooks.Open('foo.xls')
ws = workbook.Worksheets[1]

print ws.Rows[1].Value2[0,0]

This method works on my machine at least. The only thing to note is to be sure you have that Excel Interop DLL on your machine (notice that you import Excel from it on line 3). I had to put a copy of that dll file in my Rhino folder before this would work. On my system that was:

.../Users/* user name */AppData/Roaming/McNeel/Rhinoceros/6.0/scripts/

also note, if you are running in Parallels on a mac or something like that, you do need a copy of Excel on whatever OS you are running Rhino on - so I had to get a get Excel for my Windows side (I use Mac OS with Parallels to run Rhino) before this would work for me.

best,
-Ed

Thanks, it finally works. The thing was that I needed to write “#-- coding: utf-8 --” at the beginning of my script to find the file.