Exporting room data to an already existing excel template using dynamo

Hello there!

I am trying to create a script that will take all the room parameters I need from Revit and export each value to an excel worksheet corresponding its name and populate specific cells the coordinates of which I will specify. I have made some progress with existing dynamo nodes and packages but I believe python would be a more efficient alternative. Unfortunately I am still new to coding so the python script isn’t working! Basically I am trying to write a python node the will iterate through a list of room names and the worksheet names in the excel files, match the room with its respective worksheet (the worksheet name will be Space Data Sheet {name of room}) and populate the parameter values corresponding to that room in the specific cells (the coordinates of which will stay the same through all the worksheets). I really hope that makes sense and would really appreciate any feedback or advice! I will be attaching what I have been working on so far!
Thank you in advance for your help! I have been learning a lot in this forum and I hope I can give back some day once I get enough experience!


import clr
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

import openpyxl

rooms_list = IN[0]  # List of lists containing room names
excel_file_path = IN[1]  # Path to the Excel file
Rooms_Paramenter_List = IN[2]

TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument)

workbook = openpyxl.load_workbook(excel_file_path)

for room_name in rooms_list:
    if room_name in workbook.sheetnames and Rooms_Parameter_List:
    	worksheet = Space Data Sheet [room_name]
    	
        worksheet["J2"] = [1] # Use the index number as the parameter value
    else:
        print("No worksheet found for room: {room_name}")

workbook.save(excel_file_path)


TransactionManager.Instance.TransactionTaskDone()

OUT = excel_file_path

Hello @dynamofan and welcome

you can’t use openpyxl with Ironpython, you need to switch to Cpython3 engine (and install openpyxl package if you use Revit 2022)

if you want to stay on the IronPython, here 2 solutions :

Thank you for the reply! I understand that I need to install openpyxl however I am failing to do so since I cant run “Command Prompt” as Admin. Am I missing anything here or is there perhaps a simpler way to extract info from excel without the need of openpyxl package! Thanks a lot once again!

I believe that IronPython3 would work here as well, right?

not at the moment the python packages python coded in C are not currently supported in IronPython3 (there is work in progress to support these packages ‘IronClad’ project)

but OpenXml or Excel Interrop works well with IronPython3

1 Like

I think you should take it gradually by starting by learning the basics of Python, then trying with Excel interop (which is easier to learn than OpenXml)

an alternative is to migrate to Revit 2023 where openpyxl is installed by default with CPython3 engine