[英]How to export only Spotfire Selected columns with IronPython script?
I use a working IronPython script to export in an xls file all the columns of a Spotfire Table. 我使用有效的IronPython脚本在xls文件中导出Spotfire表的所有列。
I want to update the below script to only export “Selected columns” (see picture) defined in the Column menu of the Table Properties. 我想更新以下脚本以仅导出在“表格属性”的“列”菜单中定义的“选定列” (参见图片)。
With more than 1500 columns among 50 tables it is not an option to hard coded/predefined the list of column to be exported. 50个表中有1500多个列,因此不能硬编码/预定义要导出的列的列表。 If I change the columns selection in the Table Properties only those selected column must be exported.
如果更改“表属性”中的列选择,则仅必须导出那些选择的列。
In the example I would like to have in my Test.xls file only content of the three columns “studyid”, “etcd” and “element” of my TE table. 在该示例中,我想在我的Test.xls文件中仅包含TE表的三列“ studyid”,“ etcd”和“ element”的内容。
With the below script “domain” and “tesrcdtc” column are also exported. 使用以下脚本,“域”和“ tesrcdtc”列也将导出。
IronPython script: IronPython脚本:
from Spotfire.Dxp.Data.Export import DataWriterTypeIdentifiers
from System.IO import File, Directory
from System.Collections.Generic import List
from Spotfire.Dxp.Data import *
from Spotfire.Dxp.Application.Visuals import *
DataTable = Document.ActiveDataTableReference
Rows = Document.ActiveFilteringSelectionReference.GetSelection(DataTable).AsIndexSet()
writer = Document.Data.CreateDataWriter(DataWriterTypeIdentifiers.ExcelXlsDataWriter)
stream = File.OpenWrite("C:/Export/Test.xls")
Cols = []
for col in DataTable.Columns:
Cols.append(col.Name)
writer.Write(stream, DataTable, Rows, Cols)
stream.Close()
from Spotfire.Dxp.Data.Export import DataWriterTypeIdentifiers
from System.IO import File, Directory
from System.Collections.Generic import List
from Spotfire.Dxp.Data import *
from Spotfire.Dxp.Application.Visuals import *
DataTable = Document.ActiveDataTableReference
Rows = Document.ActiveFilteringSelectionReference.GetSelection(DataTable).AsIndexSet()
writer = Document.Data.CreateDataWriter(DataWriterTypeIdentifiers.ExcelXlsDataWriter)
stream = File.OpenWrite("C:/Export/Test.xls")
Cols = [“studyid”,“etcd”,“element”] # Instead of adding all the columns, just add the ones you want
writer.Write(stream, DataTable, Rows, Cols)
stream.Close()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.