2
votes

I use a working IronPython script to export in an xls file all the columns of a Spotfire Table.

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. If I change the columns selection in the Table Properties only those selected column must be exported.

Selected colums

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.

With the below script “domain” and “tesrcdtc” column are also exported.

IronPython script:

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()
1
Question has been updated to clarify the problem. Hope it is clear now.Christophe Liber

1 Answers

0
votes
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()