2016-10-10 197 views
0

我是IronPython的新手,并尝试使用下面的代码将我的交叉表从Spotfire导出到Excel。IronPython脚本帮助 - 在SPotfire中将交叉表导出到Excel

如何修改此脚本以包含定义vizTable?

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() 

我不断收到下面的错误。我已经设置了一个脚本参数,但不知道将脚本合并到哪里。

错误消息:

saveFilename= C:\Users\D565046\Desktop\test 3.xlsx
Traceback (most recent call last):
File "Spotfire.Dxp.Application.ScriptSupport", line unknown, in ExecuteForDebugging
File "<string>", line 14, in <module>
NameError: name 'vizTable' is not defined

Microsoft.Scripting.Runtime.UnboundNameException: name 'vizTable' is not defined
at IronPython.Runtime.PythonContext.MissingName(SymbolId name)
at Microsoft.Scripting.Runtime.LanguageContext.LookupName(CodeContext context, SymbolId name)
at $456##456(Closure , Scope , LanguageContext)
at Spotfire.Dxp.Application.ScriptSupport.IronPythonScriptEngine.ExecuteForDebugging(String scriptCode, Dictionary`2 scope, Stream outputStream)

enter image description here

回答

1

我相信两件事情都在这里发生。 1)vizTable应在脚本下方的“脚本参数”区域中定义,完全如您对exportWellHeader所做的操作以及引用要导出的可视化(交叉表)一样。 2)我相信第14行是不正确的,你不应该有像exportWellHeader这样的东西。我认为它应该读起来更像: vizTable.As[CrossTablePlot]().ExportText(DataWriterTypeIdentifiers.ExcelXlsxDataWriter, stream)

来源:http://easyspotfire.blogspot.com/2014/11/export-cross-table-visualization-to-file.html

请注意,在引用链接,脚本作者是将数据导出到一个文本文件,而不是一个Excel文件。

+0

谢谢你的帮助,但我仍然得到下面的错误,当我替换它仍然给我下面的错误。有什么建议么? SaveFilename = C:\用户\桌面\ rf.xlsx 回溯(最近通话最后一个): 文件 “Spotfire.Dxp.Application.ScriptSupport”,行未知,在ExecuteForDebugging 文件 “”,14号线在 NameError:name'vizTable'is not defined Microsoft.Scripting.Runtime.UnboundNameException:name'vizTable'is – gingineer

+0

嗨,你是否包含'vizTable'作为脚本参数?该错误似乎说vizTable没有定义。是否有可能用新的屏幕截图更新你的文章? – HalcyonicDays