首页 > 解决方案 > 如何更新所有表并动态获取表名?

问题描述

我在 Tibco Spotfire 工作,想要一种方法来更新分析中的所有数据源。这可以使用此处描述的脚本来完成:Spotfire - 如何添加重新加载按钮

我已经这样实现了:

# * * *
#
# Update tables based on:
# https://stackoverflow.com/questions/49997755/spotfire-how-to-add-a-reload-button
#
# * * *

import ctypes
from System.Collections.Generic import List, Dictionary 
from Spotfire.Dxp.Data import DataTable 
from System.Collections import ArrayList

ctypes.windll.user32.MessageBoxW(0, "About to refresh all data from databases...", "Data Update", 1)

tables = ArrayList()
tables.Add(Document.Data.Tables["raw_table_col_detail"]) 
tables.Add(Document.Data.Tables["age_group"]) 
Document.Data.Tables.Refresh(tables)

ctypes.windll.user32.MessageBoxW(0, "Done with update.", "Data Update", 1)

我现在想实现它,以便它适用于任何分析。如何获取可用表的列表,然后遍历该列表(即如何动态地执行上述操作而无需指定表名、“raw_table_col_detail”、“age_group”等)。

标签: pythonspotfire

解决方案


根据您使用的 Spotfire 版本,这里列出了几个选项https://community.tibco.com/wiki/how-refresh-or-reload-data-using-ironpython-script-tibco-点火

您可以遍历它们并一次刷新一个

import ctypes
ctypes.windll.user32.MessageBoxW(0, "About to refresh all data from databases...", "Data Update", 1)
for t in Document.Data.Tables:
    t.Refresh()
ctypes.windll.user32.MessageBoxW(0, "Done with update.", "Data Update", 1)

或者您可以将它们推送到一个数组并一起刷新它们

import ctypes
from System.Collections import ArrayList
tables = ArrayList()
for t in Document.Data.Tables:
    tables.Add(t)
ctypes.windll.user32.MessageBoxW(0, "About to refresh all data from databases...", "Data Update", 1)
Document.Data.Tables.Refresh(tables)
ctypes.windll.user32.MessageBoxW(0, "Done with update.", "Data Update", 1)

推荐阅读