Export Table to excel issue:

Hi - Export Table to excel issue: I'm trying to use the script copied below:
import System
from System.IO import FileStream, FileMode
from Spotfire.Dxp.Application.Visuals import TablePlot
from Spotfire.Dxp.Data.Export import DataWriterTypeIdentifiers
import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import SaveFileDialog

# GETS THE FILE PATH FROM THE USER THROUGH A FILE DIALOG
SaveFile = SaveFileDialog()
SaveFile.Filter = "Spotfire Text Data Format (*.xlsx)|*.xls"
SaveFile.ShowDialog()

if SaveFile.FileName=="":
  # user does not select a file (cancel button)
 saveFilename = ""
else:
 saveFilename = SaveFile.FileName
 print "saveFilename=", saveFilename

  # Export Table data to the file
try:
 stream = FileStream(saveFilename, FileMode.Create)
 vizTable.As[TablePlot]().ExportData(DataWriterTypeIdentifiers.ExcelXlsxDataWriter, stream)
 print "stream.Length = ", stream.Length
finally:
 stream.Dispose()

I am getting the following error when trying to use the script in a action control button:

System.MissingMemberException: 'NoneType' object has no attribute 'ExportData'
  at _stub_$76##76(Closure , CallSite , Object , CodeContext )
  at Microsoft.Scripting.Actions.MatchCaller.Call2[T0,T1,TRet](Func`4 target, CallSite site, Object[] args)
  at Microsoft.Scripting.Actions.CallSite`1.UpdateAndExecute(Object[] args)
  at Microsoft.Scripting.Actions.UpdateDelegates.Update2[T,T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
  at <module>$58##58(Closure , Scope , LanguageContext )
  at Spotfire.Dxp.Application.ScriptSupport.IronPythonScriptEngine.ExecuteForDebugging(String scriptCode, Dictionary`2 scope, Stream outputStream)
  at Spotfire.Dxp.Application.Scripting.ScriptManager.<>c__DisplayClass14.<ExecuteScriptForDebugging>b__f()
  at Spotfire.Dxp.Framework.Commands.CommandHistory.Transaction(Executor executor, Boolean visible, Boolean sticky, Guid stickyGuid)
  at Spotfire.Dxp.Framework.Commands.CommandHistory.Transaction(String displayName, Executor executor)
  at Spotfire.Dxp.Framework.DocumentModel.DocumentNode.Transaction(String displayName, Executor executor)
  at Spotfire.Dxp.Application.Scripting.ScriptManager.ExecuteScriptForDebugging(String scriptCode, Dictionary`2 scriptArguments, String& output)
  at Spotfire.Dxp.Forms.Framework.Scripting.ScriptEditDialog.RunButton_Click(Object sender, EventArgs e)

Any help would be appreciated. I'm using potfire 5.5 and have no need for this to work via webplayer. Thanks!

(1) Answer

Login