This article details how to export data from Spotfire® using IronPython script and C#
Introduction
This example shows how to export data from Spotfire using IronPython script and C#.
It illustrates how to export data from Spotfire to file(s) in Sbdf and XLS formats. However, the same operation can be used to export to any of the formats that are part of the DataWriterTypeIdentifiers enumeration.
Note: You may check the following API reference for the pre-defined outputs that may be used with the method described in this article
API Reference: DataWriterTypeIdentifiers Class
This example uses the active filtering to determine what rows should be exported. This can easily be changed to other selections, for example a marking.
Code samples
# Copyright © 2017. TIBCO Software Inc. Licensed under TIBCO BSD-style license. # Python Script Implementation for TIBCO Spotfire Binary Data Format (*.Sbdf) from Spotfire.Dxp.Data.Export import DataWriterTypeIdentifiers from System.IO import File # Set the DataTable you want to use. table = Document.ActiveDataTableReference # Create the data writer writer = Document.Data.CreateDataWriter(DataWriterTypeIdentifiers.SbdfDataWriter) # Set the selection (row indexes) that determines what rows will be exported selection = Document.ActiveFilteringSelectionReference.GetSelection(table).AsIndexSet() stream = File.Open("c:tempSpotfireExport.sbdf", FileMode.Create) names = [] for col in table.Columns: names.append(col.Name) writer.Write(stream, table, selection, names) stream.Close()
// Copyright © 2017. TIBCO Software Inc. Licensed under TIBCO BSD-style license. // C# Implementation for Microsoft Excel Workbook (*.Xls): // Set the DataTable you want to use. DataTable dt = app.Document.ActiveDataTableReference; // Create the data writer var writer = app.CreateDataWriter(DataWriterTypeIdentifiers.ExcelXlsDataWriter); // Set the selection (row indexes) that determines what rows will be exported var filtering = app.Document.ActiveFilteringSelectionReference.GetSelection(app.Document.ActiveDataTableReference).AsIndexSet(); Stream stream; try { stream = File.OpenWrite(@"C:TempSpotfireExport.xls"); } catch (UnauthorizedAccessException) { return; } List names = new List(); foreach (DataColumn col in dt.Columns) { names.Add(col.Name); } writer.Write(stream, dt, filtering, names); stream.Flush(); stream.Dispose();
See also
References
- API Reference: Spotfire Analyst
- API Reference: AnalysisApplication.CreateDataWriter Method
- API Reference: DataWriter Class
- API Reference: DataWriterTypeIdentifiers Class
License: TIBCO BSD-Style License
Recommended Comments
There are no comments to display.