Jump to content

Recommended Posts

Posted

#I am trying to replace multiple files in Spotfire using a python script, script works perfectly well when it finds all the files in the destination folder, however, if even a single file is not present in the destination folder then it gives an alert that "file XYZ.xlsx is not found in the destination folder" and the code will not replace a single file.

#Below is the code which works if all the files are found in the destination folder:

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 theTblnm

for table in Document.Data.Tables:

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

Tblnm=table.Name[8:20]

sourceView=table.GenerateSourceView()

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

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

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

if op.CanReplaceDataFlow():

op.ReplaceDataFlow(dataFlow)

 

#I have tried the below code it works in the python window but crashes the .dxp when I openthe data table property.

try:

if op.CanReplaceDataFlow():

op.ReplaceDataFlow(dataFlow)

except:

print(Tblnm)

Posted

Hi Rayees,

Thanks for looking into this, I am using version 7.11.

I have used:

import clr

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

and after removing this part, Spotfire is not crashing anymore, however, the code is still not replacing the data source of the files available in a folder.can you help

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