Here's a sample script to programmatically via IronPython export a data table as CSV
from Spotfire.Dxp.Data.Export import DataWriterTypeIdentifiers
from System.IO import File
writer = Document.Data.CreateDataWriter(DataWriterTypeIdentifiers.ExcelXlsDataWriter)
table = Document.ActiveDataTableReference #OR pass the DataTable as parameter
filtered = Document.ActiveFilteringSelectionReference.GetSelection(table).AsIndexSet() #OR pass the filter
stream = File.OpenWrite("PATH/NAME.csv")
names = []
for col in table.Columns:
names.append(col.Name)
writer.Write(stream, table, filtered, names)
stream.Close()
Note: the path you pass to the File.OpenWrite function is relative to the machine running the analysis; this means that on the Web Player, unless you find a way to stream the data back to the user browser, the end user will never receive the file
Is there a way to do this with filtering AND markings?
ReplyDeleteI don't remember exactly since I've not been wokring on this for quite some time :(
ReplyDeleteIf the 'filtered' variable contains your filtered dataset then I think it would be possible to match entries there with the marked entries you can retrieve from the marking itself and then pass only this resulting dataset to the Write function.
Or maybe instead of using 'table' as the full table, restrict that to only the marked entries before calling Write.
I would need to go through the APIs again to verify exactly what is returned though, sorry