# Open Excel File with Python

**URL:** <https://forum.dynamobim.com/t/open-excel-file-with-python/18792>\
**Category:** Developers\
**Created:** [February 5, 2018, 12:28pm UTC](https://forum.dynamobim.com/t/open-excel-file-with-python/18792 "2018-02-05T12:28:14Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jorge\_Villarroel](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jorge_villarroel/32/23619_2.png) [@Jorge\_Villarroel](https://forum.dynamobim.com/u/Jorge_Villarroel)\
**Post date:** [February 5, 2018, 12:28pm UTC](https://forum.dynamobim.com/t/open-excel-file-with-python/18792/1 "2018-02-05T12:28:14Z")

</div>

Hi All,

Quick question. How do I open a particular Excel file using python? Don’t want to write or read the info, just open the file?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![PauLtus](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paultus/32/48502_2.png) [@PauLtus](https://forum.dynamobim.com/u/PauLtus)\
**Post date:** [February 5, 2018, 12:34pm UTC](https://forum.dynamobim.com/t/open-excel-file-with-python/18792/2 "2018-02-05T12:34:07Z")

</div>

Why exactly do you want to use Python code for that?

You can simply use the Excel.ReadFromFile node to read data from an Excel file and an Excel file will always open to let Dynamo do so.

A script like the following should do the job:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/0/50d44fa66c62023803d51bf591e6d1729ae8c6ab.png)

---

<div class="post-metadata">

**Author:** ![Jorge\_Villarroel](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jorge_villarroel/32/23619_2.png) [@Jorge\_Villarroel](https://forum.dynamobim.com/u/Jorge_Villarroel)\
**Post date:** [February 5, 2018, 12:37pm UTC](https://forum.dynamobim.com/t/open-excel-file-with-python/18792/3 "2018-02-05T12:37:22Z")

</div>

Hi @PauLtus, I’d like to use it first, to know how can I call excel files from python and also because it is a part of a larger python code.

The example you mentioned it is what I want but using only python. Is it possible?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Tom\_James](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/tom_james/32/22277_2.png) [@Tom\_James](https://forum.dynamobim.com/u/Tom_James)\
**Post date:** [February 5, 2018, 12:38pm UTC](https://forum.dynamobim.com/t/open-excel-file-with-python/18792/4 "2018-02-05T12:38:55Z")

</div>

> **[Stack Overflow - Where Developers Learn, Share, & Build Careers](https://stackoverflow.com/)**
>
> Stack Overflow | The World’s Largest Online Community for Developers

---

<div class="post-metadata">

**Author:** ![PauLtus](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paultus/32/48502_2.png) [@PauLtus](https://forum.dynamobim.com/u/PauLtus)\
**Post date:** [February 5, 2018, 12:42pm UTC](https://forum.dynamobim.com/t/open-excel-file-with-python/18792/5 "2018-02-05T12:42:11Z")

</div>

Well, you probably can.

But in that case maybe you can just load in the file in a similar sense to as you’d do with other inputs:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/e/ae9082764c2064994d3fb9d9dd95a74b60458465.png)  
Following that, I’m an absolute Python amateur.  
Might be a case where you’d just want to ask it on a Python forum.

---

<div class="post-metadata">

**Author:** ![Jorge\_Villarroel](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jorge_villarroel/32/23619_2.png) [@Jorge\_Villarroel](https://forum.dynamobim.com/u/Jorge_Villarroel)\
**Post date:** [February 5, 2018, 12:43pm UTC](https://forum.dynamobim.com/t/open-excel-file-with-python/18792/6 "2018-02-05T12:43:19Z")

</div>

Thanks @PauLtus

---

<div class="post-metadata">

**Author:** ![oliver.green](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/oliver.green/32/22443_2.png) [@oliver.green](https://forum.dynamobim.com/u/oliver.green)\
**Post date:** [February 5, 2018, 1:03pm UTC](https://forum.dynamobim.com/t/open-excel-file-with-python/18792/7 "2018-02-05T13:03:30Z")

</div>

It’s possible! If you want to background-open the Excel file for editing (as part of your Python script) you can double-click on Konrad’s Write Excel node in the Bumblebee package to read through the process.

I have no idea about your level of experience - it’s not for beginners. Also, check out the Microsoft Office Interop library for Excel. If this process doesn’t make sense to you, I would just suggest using Dynamo.

---

<div class="post-metadata">

**Author:** ![Jorge\_Villarroel](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jorge_villarroel/32/23619_2.png) [@Jorge\_Villarroel](https://forum.dynamobim.com/u/Jorge_Villarroel)\
**Post date:** [February 5, 2018, 1:52pm UTC](https://forum.dynamobim.com/t/open-excel-file-with-python/18792/8 "2018-02-05T13:52:31Z")

</div>

Thanks @oliver.green. I managed to do this (the path to the excel file was stored in my project information):

```
import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
import Autodesk

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager

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

doc = DocumentManager.Instance.CurrentDBDocument
ruta = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_ProjectInformation).ToElements()[0].LookupParameter('RUTA PLANILLA MUROS').AsString()

#abrir el libro de excel y extrae las columans relevantes
ex = Excel.ApplicationClass()
ex.Visible = True

workbook = ex.Workbooks.Open(ruta)

OUT = 'Listo!' 

```

Cheers!

---

<div class="post-metadata">

**Author:** ![MAIA17112](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@MAIA17112](https://forum.dynamobim.com/u/MAIA17112)\
**Post date:** [February 24, 2020, 1:46pm UTC](https://forum.dynamobim.com/t/open-excel-file-with-python/18792/9 "2020-02-24T13:46:58Z")

</div>

> [@Jorge\_Villarroel](#):
>
> OUT = ‘Listo!’

Hi, I am trying to use your code but I have an error \>\>  
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.  
Traceback (most recent call last):  
File “”, line 16, in   
AttributeError: ‘NoneType’ object has no attribute ‘AsString’

and there is no option to add the file path to make sure that file will be updated?

---

<div class="post-metadata">

**Author:** ![Deniz\_Maral](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/deniz_maral/32/80323_2.png) [@Deniz\_Maral](https://forum.dynamobim.com/u/Deniz_Maral)\
**Post date:** [February 24, 2020, 2:05pm UTC](https://forum.dynamobim.com/t/open-excel-file-with-python/18792/10 "2020-02-24T14:05:46Z")

</div>

What are you trying to do? Do you use same code? Can you share your code?

> [@Jorge\_Villarroel](#):
>
> 'RUTA PLANILLA MUROS

He has that parameter in project. Do you have the same?

---

<div class="post-metadata">

**Author:** ![MAIA17112](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@MAIA17112](https://forum.dynamobim.com/u/MAIA17112)\
**Post date:** [February 24, 2020, 2:27pm UTC](https://forum.dynamobim.com/t/open-excel-file-with-python/18792/11 "2020-02-24T14:27:37Z")

</div>

I try to update file excel when I edit it without loading it again… in a traditional way when I use read excel file and make file from the path it’s working but when I make edit on excel file there is no change in dynamo until reload it again ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/9/297c7e5dd1ff5cd8d79b1b49dd31474c7349a520.png)

---

<div class="post-metadata">

**Author:** ![MAIA17112](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@MAIA17112](https://forum.dynamobim.com/u/MAIA17112)\
**Post date:** [February 24, 2020, 2:32pm UTC](https://forum.dynamobim.com/t/open-excel-file-with-python/18792/12 "2020-02-24T14:32:17Z")

</div>

[door pts.xlsx](https://forum.dynamobim.com/uploads/short-url/8TwAcW3dImiDIRmJae3Uxp7O5dR.xlsx) (9.2 KB) [test 2.dyn](https://forum.dynamobim.com/uploads/short-url/gZhNJ0m7Nu44vl3c1Ptpiwm7GuA.dyn) (4.1 KB)

---

<div class="post-metadata">

**Author:** ![Deniz\_Maral](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/deniz_maral/32/80323_2.png) [@Deniz\_Maral](https://forum.dynamobim.com/u/Deniz_Maral)\
**Post date:** [February 24, 2020, 2:51pm UTC](https://forum.dynamobim.com/t/open-excel-file-with-python/18792/13 "2020-02-24T14:51:44Z")

</div>

You don’t need Python for that. If you use File Path \> File From Path\> Data.ImportExcel combination and make a change in excel and then save it in Automatic mode in Dynamo, it will be updated automatically.

---

<div class="post-metadata">

**Author:** ![MAIA17112](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@MAIA17112](https://forum.dynamobim.com/u/MAIA17112)\
**Post date:** [February 25, 2020, 11:27am UTC](https://forum.dynamobim.com/t/open-excel-file-with-python/18792/14 "2020-02-25T11:27:54Z")

</div>

thanks deniz ^^
