Jump to content

Replace Spotfire data table using property control and Iron python script without dialog box


Luke George 2

Recommended Posts

I'm looking for a way to replace the data table in spotfire using a property control and Iron python script.

I found some other scripts to do this, but they bring up a dialog box to select the replacement data table. I would like to do this without a dialog box selection.

I would like the property control to be a drop down list of fixed values where the fixed values match table names in a folder. Upon selecting any filename in the drop down list, the corresponding table automatically replaces the existing data table.

Link to comment
Share on other sites

You can use below sample script as a reference and make changes to the document property , data table name and specify the folder path

from Spotfire.Dxp.Data import *

#read the file name from drop down

fileName=Document.Properties["fileName"]

#If need to specify any settings for the file

readerSettings = TextDataReaderSettings()

#create a datasource

dSource = TextFileDataSource(r"c:\filepath\"+fileName,readerSettings)

#replace datatable

Document.Data.Tables["myTableName"].ReplaceData(dSource)

Link to comment
Share on other sites

Hi Shandilya,Thankyou for your help. I have implemented the code:

from Spotfire.Dxp.Data import *

#read the file name from drop down

fileName=Document.Properties["Property1"]

#If need to specify any settings for the file

readerSettings = TextDataReaderSettings()

#create a datasource

dSource = TextFileDataSource(r"D:\FolderDATA\"+fileName,readerSettings)

#replace datatable

Document.Data.Tables["Analysis"].ReplaceData(dSource)But I get an error:NameError: name 'TextDataReaderSettings' is not definedI assume this is because I have nothing in TextDataReaderSettings(), but I have no specific settings for the files I'm loading. They are all csv files that are identically formatted. How should I adjust the scriptThankyou

Link to comment
Share on other sites

Hi Shandilya,

 

Thank you for your help again.

 

I added "from Spotfire.Dxp.Data.Import import TextFileDataSource, TextDataReaderSettings" and I no longer get the error, however it now says "Exception: File not found: D:\FolderDATA\File1" even though File1 is in the folder. I changed the file name to fileName=Document.Properties["DrillholeSelection"]+".txt" and the code seems to work now. The only problem is the entire document gets loaded as a single column even though the spreadsheet has over 50 columns... And idea how to fix this

 

Thank you

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...