Tarun Parmar Posted June 26, 2019 Share Posted June 26, 2019 Below script looks at two Cross Table visualizations and converts them to two seprate Data Tables. I then change these two Data Table to another set of Cross Tables to summarize on a higher level Issue is every time I run it, it over rides the later Cross Table settings. Also I see the script somehow by default converts a numeric column to string, I am looking for a way to keep the numeric column intact so that I don't have to update the data types every timeI run the script. from System.IO import * from System.IO import Path, File, StreamWriter from Spotfire.Dxp.Data import DataTableSaveSettings from Spotfire.Dxp.Application.Visuals import CrossTablePlot from Spotfire.Dxp.Data.Import import TextFileDataSource from Spotfire.Dxp.Data.Import import TextDataReaderSettings from Spotfire.Dxp.Application.Visuals import TablePlot from Spotfire.Dxp.Application.Visuals import VisualTypeIdentifiers #Export CrossTable data to the MemoryStream mStream = MemoryStream(); mWriter = StreamWriter(mStream); CrossTable1.As[CrossTablePlot]().ExportText(mWriter) #Reset stream back to the beginning mStream.Seek(0, SeekOrigin.Begin) #Add cross table data back into Spotfire using TextFileDataSource readerSet = TextDataReaderSettings() readerSet.Separator = "t" readerSet.AddColumnNameRow(0) textDataSource = TextFileDataSource(mStream, readerSet) for table in Document.Data.Tables: if table.Name == "CrossTableData1": Document.Data.Tables.Remove(table.Name) myNewTable = Document.Data.Tables.Add("CrossTableData1",textDataSource) #If you want to change the data table to be embedded and not linked, use the following code settings = DataTableSaveSettings (myNewTable,False, False); Document.Data.SaveSettings.DataTableSettings.Add(settings); #Export CrossTable data to the MemoryStream mStream = MemoryStream(); mWriter = StreamWriter(mStream); CrossTable2.As[CrossTablePlot]().ExportText(mWriter) #Reset stream back to the beginning mStream.Seek(0, SeekOrigin.Begin) #Add cross table data back into Spotfire using TextFileDataSource readerSet = TextDataReaderSettings() readerSet.Separator = "t" readerSet.AddColumnNameRow(0) textDataSource = TextFileDataSource(mStream, readerSet) for table in Document.Data.Tables: if table.Name == "CrossTableData2": Document.Data.Tables.Remove(table.Name) myNewTable = Document.Data.Tables.Add("CrossTableData2",textDataSource) #If you want to change the data table to be embedded and not linked, use the following code settings = DataTableSaveSettings (myNewTable,False, False); Document.Data.SaveSettings.DataTableSettings.Add(settings); Link to comment Share on other sites More sharing options...
Sayali Patil Posted July 11, 2019 Share Posted July 11, 2019 Hello, You can explicitly set the data types of the columns like - readerSet.SetDataType(0, DataType.String) readerSet.SetColumnName(0, 'Row ID') readerSet.SetDataType(1, DataType.Real) readerSet.SetColumnName(1, 'Calculated Value') Link to comment Share on other sites More sharing options...
Tarun Parmar Posted July 16, 2019 Author Share Posted July 16, 2019 How do i specify the table Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now