IronPython Script Help - Export Cross Table to Excel in SPotfire
<p>I am new to IronPython and trying to use the below code to export my cross table from Spotfire to excel. </p>

<p>How do I modify this script to include defining the vizTable?  </p>

<pre><code>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  
SaveFile = SaveFileDialog()   #GETS THE FILE PATH FROM THE USER THROUGH A FILEDIALOG
SaveFile.Filter = "xls Format (*.xls)|*.xlsx|*.xls|*.xlsx"
SaveFile.ShowDialog()
saveFilename = SaveFile.FileName
print "saveFilename=", saveFilename
stream = FileStream(saveFilename, FileMode.Create) #Export Table data to the file
vizTable.As[exportWellHeader]().ExportData(DataWriterTypeIdentifiers.ExcelXlsxDataWriter, stream)
stream.Dispose()
</code></pre>

<p>I keep getting the  below error. I have set a script parameter but do not know where to incorporate into the script. </p>

<p>Error messages:</p>

<blockquote>
  <p>saveFilename= C:\Users\D565046\Desktop\test 3.xlsx<br>
  Traceback (most recent call last):<br>
  File "Spotfire.Dxp.Application.ScriptSupport", line unknown, in  ExecuteForDebugging<br>
  File "&lt;string&gt;", line 14, in &lt;module&gt;<br>
  NameError: name 'vizTable' is not defined  </p>
  
  <p>Microsoft.Scripting.Runtime.UnboundNameException: name 'vizTable' is not defined<br>
     at IronPython.Runtime.PythonContext.MissingName(SymbolId name)<br>
     at Microsoft.Scripting.Runtime.LanguageContext.LookupName(CodeContext context, SymbolId name)<br>
     at $456##456(Closure , Scope , LanguageContext )<br>
     at   Spotfire.Dxp.Application.ScriptSupport.IronPythonScriptEngine.ExecuteForDebugging(String scriptCode, Dictionary`2 scope, Stream outputStream)  </p>
</blockquote>

<p><img src="https://i.stack.imgur.com/mDH8K.png" alt="enter image description here"></p>