0

我正在为 Microsoft Project 开发 Office 任务窗格加载项,但遇到了严重的限制。

创建一个新项目文件后,我加载了任务窗格应用程序,它有一个子函数,它读取Office.context.document.url属性,它应该具有文件的完整路径。

很明显,一开始它是空的,因为它是一个未保存的项目,但是在我保存项目并再次触发子功能后,url仍然是空的。

我想,文档对象在保存过程中的任何时候都不会重新加载。我怎样才能手动做到这一点?如果它是可能的...

这是返回项目路径的子函数:

function getProjectPath() {
    var documenturl = Office.context.document.url;
    if (documenturl == null || documenturl == "") {
        return "";
    }
    else {
        return documenturl;
    }
}
4

1 回答 1

2

这个问题是关于Project的,谁不支持这个方法,但是想要动态访问Word、Excel和PPT的文件url,我推荐你使用getFilePropertiesAsync方法。

这是有关如何使用它的示例:

function getFileUrl() {
    //Get the URL of the current file.
    Office.context.document.getFilePropertiesAsync(function (asyncResult) {
        var fileUrl = asyncResult.value.url;
        if (fileUrl == "") {
            showMessage("The file hasn't been saved yet. Save the file and try again");
        }
        else {
            showMessage(fileUrl);
        }
    });
}

于 2016-09-07T15:25:26.780 回答