# Read and add in a dictionary values from EXCEL - SOLVED

**URL:** <https://discourse.mcneel.com/t/read-and-add-in-a-dictionary-values-from-excel-solved/176154>\
**Category:** Scripting\
**Tags:** windows, mac, eto, python\
**Created:** [February 20, 2024, 4:41pm UTC](https://discourse.mcneel.com/t/read-and-add-in-a-dictionary-values-from-excel-solved/176154 "2024-02-20T16:41:11Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![antoine](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/antoine/32/770471_2.png) [@antoine](https://discourse.mcneel.com/u/antoine)\
**Post date:** [February 20, 2024, 4:41pm UTC](https://discourse.mcneel.com/t/read-and-add-in-a-dictionary-values-from-excel-solved/176154/1 "2024-02-20T16:41:12Z")

</div>

Hello,  
I actually have a python code to read and retrieve data values into a dictionary using import CSV and DictReader.  
Simple datas well organized of customers (name, email, phone…)  
It works great, but I would like to know if reading data from EXCEL file could be done easily? (to avoid export in csv the excel base file)  
Which import need I use?  
I would like to have a cross system between MAC and PC

Thank you for your helps

---

<div class="post-metadata">

**Author:** ![sadra](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/sadra/32/687498_2.png) [@sadra](https://discourse.mcneel.com/u/sadra)\
**Post date:** [February 20, 2024, 5:45pm UTC](https://discourse.mcneel.com/t/read-and-add-in-a-dictionary-values-from-excel-solved/176154/2 "2024-02-20T17:45:33Z")

</div>

If I understand your question correctly, you’re asking `how to read an Excel file using Python`. With the addition of the `CPython component(python 3 script component)` to Rhino 8, **you can install libraries to accomplish this task** (`pip install ...`). There are numerous examples available online. For instance, I’ve previously created a basic solution, as shown in the image below:  
using `openpyxl` library…

 ![Annotation 2024-02-20 211047](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/d/e/0/de059cefbcca71d92f5f8673b5ec0b287f90af29.png)

---

<div class="post-metadata">

**Author:** ![antoine](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/antoine/32/770471_2.png) [@antoine](https://discourse.mcneel.com/u/antoine)\
**Post date:** [February 20, 2024, 9:26pm UTC](https://discourse.mcneel.com/t/read-and-add-in-a-dictionary-values-from-excel-solved/176154/3 "2024-02-20T21:26:07Z")

</div>

thank you Sadra, I’ll test this library, you perfectly understand my question, I was only looking for a compatible with R8 of a library for reading excel.

---

<div class="post-metadata">

**Author:** ![Ashley\_Cichocki](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ashley_cichocki/32/772286_2.png) [@Ashley\_Cichocki](https://discourse.mcneel.com/u/Ashley_Cichocki)\
**Post date:** [February 22, 2024, 8:52am UTC](https://discourse.mcneel.com/t/read-and-add-in-a-dictionary-values-from-excel-solved/176154/4 "2024-02-22T08:52:02Z")

</div>

Hi Antione,

I’m not sure of your exact needs, but often I use the components inside Lunchbox to import the data directly into Grasshopper and then plug that data into a second node that contains my scripts. Lunchbox can be found at:

[https://www.food4rhino.com/en/app/lunchbox](https://www.food4rhino.com/en/app/lunchbox)

Ash

---

<div class="post-metadata">

**Author:** ![asimonin](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/asimonin/32/592416_2.png) [@asimonin](https://discourse.mcneel.com/u/asimonin)\
**Post date:** [February 22, 2024, 11:06am UTC](https://discourse.mcneel.com/t/read-and-add-in-a-dictionary-values-from-excel-solved/176154/5 "2024-02-22T11:06:06Z")

</div>

@Ashley_Cichocki thank you but, I am not working inside Grasshopper, i was needing a library to import excel directly from a py program.🙂

---

<div class="post-metadata">

**Author:** ![AndersDeleuran](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/andersdeleuran/32/476683_2.png) [@AndersDeleuran](https://discourse.mcneel.com/u/AndersDeleuran)\
**Post date:** [February 22, 2024, 11:34am UTC](https://discourse.mcneel.com/t/read-and-add-in-a-dictionary-values-from-excel-solved/176154/6 "2024-02-22T11:34:25Z")

</div>

.NET comes with Excel interop (i.e. that one can implement in IronPython), that’ll probably cover all your needs. Here’s a quick implementation example in GHPython, but the same code should work in IronPython in Rhino 8:

 ![2024-02-22 12_31_42-Grasshopper - 210526_GHPythonExcelInterop_00 (1)_](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/6/0/6/6069a31792d97ead3df6a02934c1e133e4881963.png)  
[210526\_GHPythonExcelInterop\_00 (1).gh](https://discourse.mcneel.com/uploads/short-url/tUxE9ajRYn8vaElsCAFS8VUCvGK.gh) (1.8 KB)

---

<div class="post-metadata">

**Author:** ![asimonin](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/asimonin/32/592416_2.png) [@asimonin](https://discourse.mcneel.com/u/asimonin)\
**Post date:** [February 22, 2024, 10:49pm UTC](https://discourse.mcneel.com/t/read-and-add-in-a-dictionary-values-from-excel-solved/176154/7 "2024-02-22T22:49:42Z")

</div>

Hello @sadra,  
I installed openpyxl, then from rhino script editor, only create a py file to import and print openpyxl:  
It seems that the library is well found in rhino directory, and ready to be import, but when I use import pyxl on my py file, I have an error, module openpyxl not found…  
something wrong in the install?  
Thanks for your helps

```auto
Traceback (most recent call last):
  File "file:///C:/Users/Antoine/.rhinocode/stage/dd0jpswn.qug", line 1, in <module>
  File "C:\Users\Antoine\AppData\Local\Programs\Python\Python312\Lib\site-packages\openpyxl\ __init__.py", line 7, in <module>
    from openpyxl.workbook import Workbook
  File "C:\Users\Antoine\AppData\Local\Programs\Python\Python312\Lib\site-packages\openpyxl\workbook\ __init__.py", line 4, in <module>
    from .workbook import Workbook
  File "C:\Users\Antoine\AppData\Local\Programs\Python\Python312\Lib\site-packages\openpyxl\workbook\workbook.py", line 7, in <module>
    from openpyxl.worksheet.worksheet import Worksheet
  File "C:\Users\Antoine\AppData\Local\Programs\Python\Python312\Lib\site-packages\openpyxl\worksheet\worksheet.py", line 25, in <module>
    from openpyxl.cell import Cell, MergedCell
  File "C:\Users\Antoine\AppData\Local\Programs\Python\Python312\Lib\site-packages\openpyxl\cell\ __init__.py", line 3, in <module>
    from .cell import Cell, WriteOnlyCell, MergedCell
  Fi
le "C:\Users\Antoine\AppData\Local\Programs\Python\Python312\Lib\site-packages\openpyxl\cell\cell.py", line 26, in <module>
    from openpyxl.styles import numbers, is_date_format
  File "C:\Users\Antoine\AppData\Local\Programs\Python\Python312\Lib\site-packages\openpyxl\styles\ __init__.py", line 4, in <module>
    from .alignment import Alignment
  File "C:\Users\Antoine\AppData\Local\Programs\Python\Python312\Lib\site-packages\openpyxl\styles\alignment.py", line 5, in <module>
    from openpyxl.descriptors import Bool, MinMax, Min, Alias, NoneSet
  File "C:\Users\Antoine\AppData\Local\Programs\Python\Python312\Lib\site-packages\openpyxl\descriptors\ __init__.py", line 4, in <module>
    from .sequence import Sequence
  File "C:\Users\Antoine\AppData\Local\Programs\Python\Python312\Lib\site-packages\openpyxl\descriptors\sequence.py", line 4, in <module>
    from openpyxl.xml.functions import Element
  File "C:\Users\Antoine\AppData\Local\Programs\Python\Python312\Lib\site-packages\openpyxl\xml\functions.py", 
line 28, in <module>
    from xml.etree.ElementTree import (
ModuleNotFoundError: No module named 'xml.etree'

```

---

<div class="post-metadata">

**Author:** ![James\_Parrott](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/james_parrott/32/713265_2.png) [@James\_Parrott](https://discourse.mcneel.com/u/James_Parrott)\
**Post date:** [February 23, 2024, 11:40am UTC](https://discourse.mcneel.com/t/read-and-add-in-a-dictionary-values-from-excel-solved/176154/8 "2024-02-23T11:40:13Z")

</div>

Excel files are just xml under the hood. If you’re working in IronPython and want something simpler than the .Net interop, in pure Python, and can manage adding the path to sys.path to import a library, then I’ve tested many of the libraries in this list: [https://www.python-excel.org/](https://www.python-excel.org/)

I would’ve used openpyxl as well, but I could not easily get it to work. The simplest way to create a working Excel library I could find was a one character change to the actual code, to create a fork of pylightxl:

> **[GitHub - JamesParrott/iron\_pylightxl: A fork of pylightxl for IronPython. ...](https://github.com/JamesParrott/iron_pylightxl)**
>
> A fork of pylightxl for IronPython. Pylightxl is a light weight, zero dependency, minimal functionality excel read/writer python library - JamesParrott/iron\_pylightxl

Minimise your dependencies and try the parent project, pylightxl if you’re using Rhino 8, CPython components.

---

<div class="post-metadata">

**Author:** ![antoine](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/antoine/32/770471_2.png) [@antoine](https://discourse.mcneel.com/u/antoine)\
**Post date:** [February 23, 2024, 1:28pm UTC](https://discourse.mcneel.com/t/read-and-add-in-a-dictionary-values-from-excel-solved/176154/9 "2024-02-23T13:28:44Z")

</div>

@James_Parrott Thank you for your help, but I have a problem installing from pip, they had been installed into my rhino folder rh3,9-rh8\site-packages but any time i try to import in my py file, at launch it tells me that "no module named pylightxl "(or openpyxl)… any idea?  
Wrong install folder?

---

<div class="post-metadata">

**Author:** ![James\_Parrott](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/james_parrott/32/713265_2.png) [@James\_Parrott](https://discourse.mcneel.com/u/James_Parrott)\
**Post date:** [February 23, 2024, 2:31pm UTC](https://discourse.mcneel.com/t/read-and-add-in-a-dictionary-values-from-excel-solved/176154/10 "2024-02-23T14:31:47Z")

</div>

That error is exactly what happens when Python can’t find the library, so it’s almost certainly installed incorrectly (or the wrong path is on sys.path, if you’re using the old fashioned way).

I havent tried it yet, but it’s easier to get CPython components to handle the install with a new comment syntax. Then you don’t need to use pip at all (pip does have a custom install directory option though, but it’s an obvious unnecessary source of problems, installing packages with one Python version’s pip, to be imported by another).

---

<div class="post-metadata">

**Author:** ![antoine](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/antoine/32/770471_2.png) [@antoine](https://discourse.mcneel.com/u/antoine)\
**Post date:** [February 26, 2024, 11:05am UTC](https://discourse.mcneel.com/t/read-and-add-in-a-dictionary-values-from-excel-solved/176154/11 "2024-02-26T11:05:23Z")

</div>

seems not working on Mac… couldn’t add reference assembly…

---

<div class="post-metadata">

**Author:** ![antoine](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/antoine/32/770471_2.png) [@antoine](https://discourse.mcneel.com/u/antoine)\
**Post date:** [February 26, 2024, 2:19pm UTC](https://discourse.mcneel.com/t/read-and-add-in-a-dictionary-values-from-excel-solved/176154/12 "2024-02-26T14:19:38Z")

</div>

@James_Parrott Thank you for your helps but I have a still a problem, when lauching a simple py, to read my excel file and print datas, from the script editor, no problem with loading pylightxl, or openpyxl, but when using this py file as a button, the loading of library does not function, no modules…  
As if lauching from editor or from rhino are not loading libraries the same way… I even add in the beginning of my code # r:pylightxl but it is like if from rhino button, r: is not read to load the external library…  
Could you reproduce my problem… or not?

---

<div class="post-metadata">

**Author:** ![James\_Parrott](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/james_parrott/32/713265_2.png) [@James\_Parrott](https://discourse.mcneel.com/u/James_Parrott)\
**Post date:** [February 26, 2024, 3:45pm UTC](https://discourse.mcneel.com/t/read-and-add-in-a-dictionary-values-from-excel-solved/176154/13 "2024-02-26T15:45:30Z")

</div>

I can’t at the moment, I’m afraid. Perhaps someone else will try to reproduce it if you provide a short example script.

But basically it sounds like the context is different in the script editor, to when executing as a Button.

I actually find Rhino plug-ins are a lot trickier than Grasshopper ones (admittedly I’ve spent an order of magnitude more time on the latter). Depending on what you want to do with your code, and depending how your user will install it, the environment and context your code will be running in can change. Once that context is decided, you can work out construct a path for the libraries your code needs, e.g. in a subfolder of the regular installation folder.

If your code is just for you, it’s straightforward to use the shared working directory (`'.'`), or user’s libraries folder. Otherwise it’s possible to use the API to find the path of the Rhino document or Grasshopper document, and the paths of the special Grasshopper folders plug-ins often require installation into (libraries and user objects).

---

<div class="post-metadata">

**Author:** ![sadra](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/sadra/32/687498_2.png) [@sadra](https://discourse.mcneel.com/u/sadra)\
**Post date:** [February 27, 2024, 7:55am UTC](https://discourse.mcneel.com/t/read-and-add-in-a-dictionary-values-from-excel-solved/176154/14 "2024-02-27T07:55:31Z")

</div>

Hi, I apologize for the delayed response. I utilize Python libraries within `Grasshopper using the Python 3 component`. I haven’t tested it in the Rhino Python editor, so there might be some version-dependent bugs. Have you tried it in Grasshopper with the Python 3 component?

as you can see,there is a problem with rhino/python

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/d/a/9/da914f329499aafa485b9d9d352cb72e2ed7d874.png)

---

<div class="post-metadata">

**Author:** ![antoine](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/antoine/32/770471_2.png) [@antoine](https://discourse.mcneel.com/u/antoine)\
**Post date:** [March 7, 2024, 3:50pm UTC](https://discourse.mcneel.com/t/read-and-add-in-a-dictionary-values-from-excel-solved/176154/15 "2024-03-07T15:50:05Z")

</div>

Hello,

Just a following post on this subject to explain that I solved it , thank to @eirannejad and @nathanletwory .  
I actually use Openpyxl library, but same process could be done using Pylightxl.  
The trick is to load library on top of your program using # r:openpyxl  
Pleased find the py files which is able from a simple Eto formulary to access to a Xlsx file put in your computer to manage datas, and retrieve them in the EtoDialog and be able to populate you user texts with datas from excel.  
Inside the py file, need to adjust a picture link, and create an Excel file as pictures with Worksheet and matching columns, then populate it, and it should works.  
[PROJETFORM.py](https://discourse.mcneel.com/uploads/short-url/c6v21FRVRLw0X027ZnyT0qAem9t.py) (13.3 KB)  
Hope this could help people… Enjoy

Anyway still a bug when loading from a Mac directly from a button -runrhinoscript…because openpyxl is not loaded… but it works from Scripeditor on Mac… PC no problem 🙂  
 ![7b2a2a0d44934ec462b2d1404566d6b8f0dd3dfa_2_690x169](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/0/9/4/094fe64f1d0ec935c84faf174af31086fbe88fea.png)  
 ![b4c5631cd5227f3f88d5775173a590c93cd7b9c8_2_690x161](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/8/0/c/80cb1d0e9761d44ac93c77cbc7b2d089627651f9.png)
