Jump to content

Replacing File DataSource of multiple data tables if the table source is excel


Ankush Verma 2

Recommended Posts

Hello,

I am trying to update the python script which works very well for one data dable.

https://community.spotfire.com/wiki/how-replace-file-datasource-data-table-tibco-spotfirer-using-ironpython-scripting

I want to check the source of the data table and want to replace the table source only if it is excel and would leave all other data tables.

 

Thanks.

Link to comment
Share on other sites

  • 2 months later...

Change the data source of multiple input tables

Presteps -

*Rename the data tables whose data source need to be changed to [input] data table

Eg if table name is student rename it to [input] Student and leave others as it is.

*Folder - Document property for giving the pathof the files to be replaced

for eg if file is placed in the desktop then update the value to- //C:/Users/Desktop/ in the folder document

property, I have added the input field next to the replace data source button.

 

import clr

clr.AddReference("System.Windows.Forms")

from Spotfire.Dxp.Data.DataOperations import *

from Spotfire.Dxp.Data import *

from Spotfire.Dxp.Data import DataFlowBuilder

 

# Search for the tables which need to be replaced and assign it to Tblnm (for eg only excel)

for table in Document.Data.Tables:

if(table.Name[1:6]=="Input"):

Tblnm=table.Name[8:20]

sourceView=table.GenerateSourceView()

#get the dat table data source operation

op=sourceView.GetAllOperations[DataSourceOperation]()[0];

#build the data flow

for table in Document.Data.Tables:

dataSource= Document.Data.CreateFileDataSource(Document.Properties["Folder"]+Tblnm+".xlsx");

dataFlow = DataFlowBuilder(dataSource, Application.ImportContext).Build();

#replace the data source

if op.CanReplaceDataFlow():

op.ReplaceDataFlow(dataFlow)

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...