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!
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!
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:
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!
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:
Thanks @PauLtus
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.
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!
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?
What are you trying to do? Do you use same code? Can you share your code?
He has that parameter in project. Do you have the same?
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
door pts.xlsx (9.2 KB) test 2.dyn (4.1 KB)
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.
thanks deniz ^^