Невозможно получить доступ к защищенному члену GetService без подкласса python Document - PullRequest
0 голосов
/ 21 июня 2019

Я получаю эту ошибку: «Невозможно получить доступ к защищенному члену GetService без подкласса Python Document» в этой строке кода ... »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)

Настройте диспетчер библиотек и убедитесь, что мы можем получить доступ к указанному пути к папке

1 Ответ

0 голосов
/ 21 июня 2019

GetService для ProgressService и LibraryManager находится в приложении вместо документа. Это должно работать для вас, при условии, что ваша библиотека настроена на файловую систему вместо базы данных 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)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...