You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用IronPython实现Spotfire过滤列传输与过滤数据JSON导出?

Spotfire IronPython 需求解答与脚本修正

一、能否用IronPython获取过滤列数据并传递到另一页面?

可以实现,核心逻辑如下:

  • 获取过滤后数据:通过 Document.ActiveFilteringSelectionReference.GetSelection(table).AsIndexSet() 获取当前页面过滤后的行索引集合
  • 跨页面传递数据:
    • 方案1:将过滤后的行数据存入文档属性(Document.Properties),目标页面直接读取该属性
    • 方案2:在目标页面创建数据表格,直接将过滤后的子集写入该表格
    • 方案3:通过 Document.Pages 定位目标页面,将当前过滤上下文同步到目标页面的过滤引用

二、修正导出过滤后标记数据为JSON的脚本

原脚本存在两个关键问题:

  1. 使用 StdfDataWriter 导出STDF格式,而非JSON格式
  2. 若需导出标记数据,需通过 ActiveMarkingSelectionReference 获取标记行,而非仅依赖过滤选择

修正后的脚本(导出过滤后的标记行)

from System.IO import File
from Spotfire.Dxp.Data.Export import DataWriterTypeIdentifiers

# 配置参数:替换为你的表格名称和导出路径
TABLE_NAME = "你的表格名称"
EXPORT_PATH = "C:/Users/user/Desktop/TIBCO/Test_JSON.json"

# 获取目标数据表格
target_table = Document.Data.Tables[TABLE_NAME]

# 获取过滤后的行 + 标记行的交集(即过滤后的标记数据)
filtered_index = Document.ActiveFilteringSelectionReference.GetSelection(target_table).AsIndexSet()
marked_index = Document.ActiveMarkingSelectionReference.GetSelection(target_table).AsIndexSet()
target_index = filtered_index.Intersect(marked_index)

# 创建JSON数据写入器
json_writer = Document.Data.CreateDataWriter(DataWriterTypeIdentifiers.JsonDataWriter)

# 写入数据(使用with自动管理文件流)
with File.OpenWrite(EXPORT_PATH) as stream:
    column_names = [col.Name for col in target_table.Columns]
    json_writer.Write(stream, target_table, target_index, column_names)

可选调整

  • 若只需导出过滤后的所有数据(无需标记),删除 marked_index 和 target_index,直接传入 filtered_index 到 json_writer.Write
  • Windows路径可使用正斜杠 / 或双反斜杠 \\ 避免转义问题
  • 确保 TABLE_NAME 与Spotfire中表格名称完全匹配

内容的提问来源于stack exchange,提问作者tech_ofedges

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 13:22:08