我正尝试使用RevitPythonShell将数据从Revit写入Excel。
到目前为止,我已经将所有数据收集到一个压缩列表中,并使用枚举循环将数据按如下方式写入相应的行和列:
for index, data in enumerate(wall_zipped_list):
for count, parameters in enumerate(data):
wall_cell = worksheet_wanden.Range[(str(column_list[count]))+str(index+5)]
wall_cell.Value2 = data[count]
这个循环非常缓慢,因为它每次都在调用Value2
。一个包含大约800个墙的Revit模型需要2分钟才能写入Excel。因此,我尝试使用字典来实现不同的方法。
for k , v in data_dict.iteritems():
#print k, v[0]
worksheet_wanden.Range["A"+str(count)].Value2 = k
worksheet_wanden.Range["B"+str(count)].Value2 = v[0]
worksheet_wanden.Range["C"+str(count)].Value2 = v[1]
worksheet_wanden.Range["D"+str(count)].Value2 = v[2]
worksheet_wanden.Range["E"+str(count)].Value2 = v[3]
worksheet_wanden.Range["F"+str(count)].Value2 = v[4]
worksheet_wanden.Range["G"+str(count)].Value2 = v[5]
worksheet_wanden.Range["H"+str(count)].Value2 = v[6]
worksheet_wanden.Range["I"+str(count)].Value2 = v[7]
worksheet_wanden.Range["J"+str(count)].Value2 = v[8]
worksheet_wanden.Range["K"+str(count)].Value2 = v[9]
count += 1
这种方法已经快很多了。在Excel中,大约需要20秒钟来填充大约800行带有10列的内容。我是否错过了一些IronPython功能,可以将字典或列表写入Excel行或列?
我还尝试安装第三方模块。但这不是一个真正的选择,因为RevitPythonShell使用的是IronPython 2.7.3,我无法让pip install工作。
提前感谢您的帮助。
也许在IronPython中先写入CSV,然后以某种方式将其导入Excel会更快?