在此代码行上,我不断收到此错误,“如果没有Document的python子类,就无法访问受保护的成员GetService” ...“ progressService = Document.GetService(ProgressService)”
下面的代码旨在提示“另存为”对话框,并将文件保存到某个位置的文件夹中。
这是代码:
import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import
MessageBox,Form,MessageBoxButtons,DialogResult
from Spotfire.Dxp.Application import DocumentSaveSettings
from Spotfire.Dxp.Framework.Library import *
from Spotfire.Dxp.Framework.ApplicationModel import ProgressService
message="Would you like to save the file"
caption="Save to Library"
reply=MessageBox.Show(message,caption,MessageBoxButtons.YesNo)
def savetoLibrary():
folderName = r"C:\Users\Documents\NEW"
fileName = "TESTNEW.xlsx"
libraryManager = Document.GetService(LibraryManager)
success, libraryFolder = libraryManager.TryGetItem(folderName, LibraryItemType.Folder)
settings = DocumentSaveSettings()
Application.SaveAs(libraryFolder,fileName,LibraryItemMetadataSettings(), settings);
if reply==DialogResult.Yes:
progressService = Document.GetService(ProgressService)
progressService.ExecuteWithProgress("Saving to Library", "Saving analysis", savetoLibrary)
设置图书馆管理器,并确保我们可以访问指定的文件夹路径
答案 0 :(得分:0)
ProgressService和LibraryManager的GetService在应用程序上,而不在文档上。假设您的库是在文件系统而不是Spotfire数据库上建立的,这应该对您有用。
如果您在Spotfire数据库中存储了Spotfire库,则文件夹名和文件名分别看起来更像是'/ spotfire / library / path'和'filename'。
import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import MessageBox,Form,MessageBoxButtons,DialogResult
from Spotfire.Dxp.Application import DocumentSaveSettings
from Spotfire.Dxp.Framework.Library import *
from Spotfire.Dxp.Framework.ApplicationModel import ProgressService
message="Would you like to save the file"
caption="Save to Library"
reply=MessageBox.Show(message,caption,MessageBoxButtons.YesNo)
def savetoLibrary():
folderName = r"C:\Users\Documents\NEW"
fileName = "TESTNEW.xlsx"
libraryManager = Application.GetService(LibraryManager)
success, libraryFolder = libraryManager.TryGetItem(spotfireLibraryFolder, LibraryItemType.Folder)
settings = DocumentSaveSettings()
Application.SaveAs(libraryFolder,fileName,LibraryItemMetadataSettings(), settings);
if reply==DialogResult.Yes:
progressService = Application.GetService(ProgressService)
progressService.ExecuteWithProgress("Saving to Library", "Saving analysis", savetoLibrary)