我正在尝试使用 RevitPythonShell 将数据从 Revit 写入 Excel。
到目前为止,我已经收集了压缩列表中的所有数据,并进行了枚举 for 循环,以将数据写入相应的行和列,如下所示:
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
这种方法已经快很多了。这需要大约 20 秒才能在 Excel 中用 10 列填充大约 800 行。我是否缺少一些 IronPython 功能,您可以将字典或列表写入 Excel 行或列?
我还研究了安装 3d 派对模块。但这并不是一个真正的选择,因为 RevitPythonShell 使用 IronPython 2.7.3,我无法让 pip install 工作。
提前致谢。
首先在 IronPython 中写入 csv 然后以某种方式将其导入到 excel 中可能会更快吗?