Scott Thompson 5 Posted July 22, 2022 Share Posted July 22, 2022 I am using a text area to create a form for user input fields and a control button to save/append the data table: I created two string data type input fields for 'Rank' and 'Comment' document properties. I have used the script below applied to a control button to append user input to a data table. The script runs fine unless the text entered into the input fields contains a comma, if present the text entered with commas ends up split over a number of columns. For my end use, the user input to 'Comments" in particular will have special characters and I would like to store the entire comment (with special characters) in one column.Control buttton script :from Spotfire.Dxp.Data import AddRowsSettingsfrom System.IO import StreamWriter, MemoryStream, SeekOriginfrom Spotfire.Dxp.Data import DataType, DataTableSaveSettingsfrom Spotfire.Dxp.Data.Import import TextFileDataSource, TextDataReaderSettingsx = Document.Properties['Rank']y =Document.Properties['Comment']print(x,y)#Create some data with columns that match an existing table to which new rows need to be added. textData = "Rank,Comment,rn"+x+","+y+"rn" print(textData)#Using a Memory Stream as a placeholder to write the columns to which can then be used to make a data sourcestream = MemoryStream()writer = StreamWriter(stream)writer.Write(textData)writer.Flush()stream.Seek(0, SeekOrigin.Begin)#Settings to tell the system the data types being imported.Here it is defined as a comma separated list of column index and their data typesreaderSettings = TextDataReaderSettings()readerSettings.Separator = ","readerSettings.AddColumnNameRow(0)readerSettings.SetDataType(0, DataType.String)readerSettings.SetDataType(1, DataType.String)textDataSource = TextFileDataSource(stream,readerSettings)#Use settings here to automatically have the system match column names between the data table and the memory data source created above.settings = AddRowsSettings(Document.ActiveDataTableReference,textDataSource)#Add the rows from the datasource.Document.ActiveDataTableReference.AddRows(textDataSource,settings) Link to comment Share on other sites More sharing options...
Gaia Paolini Posted July 25, 2022 Share Posted July 25, 2022 You could try to set the separator to something other than comma, something you know does not appear in the Comment text. I suspect your real data is more complex than this example, but you could try a separator you know for sure would not appear in the data.So basically define:mySeparator='WEIRDSEPARATOR' #anything you like heretextData = "Rank"+mySeparator+"Comment"+"rn"+str(x)+mySeparator+y+"rn" ...readerSettings.Separator = mySeparator Link to comment Share on other sites More sharing options...
Scott Thompson 5 Posted July 25, 2022 Author Share Posted July 25, 2022 Thank You Gaia, Your solution worked perfectly ! Scott 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