How to use Data.ExportExcel method in a python scipt

Hi,
I was trying to use the Data.ExportExcel to write an excel file directly from a python script in Dynamo but I couldn’t use the method (the compiler said that Data is not defined). Should I import a specific library in my python script in order to use this function?

Hi @davidchivi,

The Node Data.ExportExcel is a Dynamo Node, you can’t use those nodes in a Python Script because they are written in another language/ they are not stand-alone functions.

I think it would be possible to create something similar through Python but you would have to access/ learn the Excel API to do this.

Also, why would you want to do this?

Nevertheless, this might help:

2 Likes

Thank you, I will give a look to your suggestion

@davidchivi It is possible! I just figured out how to do it:

Here is the python code:

import clr
import sys
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')
import System
from System import Array
from System.Collections.Generic import List as IList
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager 
from RevitServices.Transactions import TransactionManager 

clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")

import Autodesk 
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication 
app = uiapp.Application 
uidoc = uiapp.ActiveUIDocument

clr.AddReference("DSOffice")
import DSOffice
from DSOffice import *

filePath = IN[0]
sheetName = IN[1]
startRow = IN[2]
startCol = IN[3]
data = IN[4]
overWrite = False

list = []
for l in list:
	list.append(Array[object](l))

list2 = Array[object](list)	
list3 = Array[Array[object]](list2)

DSOffice.Data.ExportExcel(filePath, sheetName, startRow, startCol, list3, overWrite)

2 Likes

hello @leonard.moelders I was writting very similar script but I got a warning telling me the data is not an array[object]
image

regarding this issue I can see you created a definition of a list3 but I would change it like:
“for l in list:” as “for l in data:”

Oh yes. My bad. I will change that in my post :+1:

import clr
import sys
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')
import System
from System import Array
from System.Collections.Generic import List as IList
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager 
from RevitServices.Transactions import TransactionManager 

clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")

import Autodesk 
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication 
app = uiapp.Application 
uidoc = uiapp.ActiveUIDocument

clr.AddReference("DSOffice")
import DSOffice
from DSOffice import *

filePath = IN[0]
sheetName = IN[1]
startRow = IN[2]
startCol = IN[3]
data = IN[4]
overWrite = False

list = []
for l in data:
	list.append(Array[object](l))

list2 = Array[object](list)	
list3 = Array[Array[object]](list2)

DSOffice.Data.ExportExcel(filePath, sheetName, startRow, startCol, list3, overWrite)