【问题标题】:Word 2013 and Activating JS Office AppWord 2013 和激活 JS Office 应用程序
【发布时间】:2016-05-13 18:53:19
【问题描述】:

我正在尝试创建一个办公应用程序,它将从定义的列表中插入合并字段(因此用户不需要链接到数据源)到模板。我有 Word 2013 并复制了一个样板示例让我开始。我唯一的问题是我无法让示例插件显示在我的 word 环境中。有人会看一下代码,看看它在我的环境中显示是否有问题?

Manifest.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:type="TaskPaneApp">
    <Id>2b88100c-656e-4bab-9f1e-f6731d86e464</Id>
    <Version>1.0.0.0</Version>
    <ProviderName>Microsoft</ProviderName>
    <DefaultLocale>en-US</DefaultLocale>
    <DisplayName DefaultValue="Boilerplate content" />
    <Description DefaultValue="Insert boilerplate content into a Word document." />
    <Hosts>
        <Host Name="Document"/>
    </Hosts>
    <DefaultSettings>
        <SourceLocation DefaultValue="home.html" />
    </DefaultSettings>
    <Permissions>ReadWriteDocument</Permissions>
</OfficeApp>

home.js 文件

Office.initialize = function (reason) {
// Checks for the DOM to load using the jQuery ready function.
$(document).ready(function () {
// After the DOM is loaded, add-in-specific code can run.
// Display initialization reason.
if (reason == "inserted")
write("The add-in was just inserted.");

if (reason == "documentOpened")
write("The add-in is already part of the document.");
});
}

// Function that writes to a div with id='message' on the page.
function write(message){
document.getElementById('message').innerText += message; 
}

home.html 文件

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <title>Boilerplate text app</title>
    <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.4.min.js" type="text/javascript"></script>
    <script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>
    <script src="home.js" type="text/javascript"></script>
    </head>
    <body>
        <div>
                <h1>Welcome</h1>
        </div>
        <div>
                <p>This sample shows how to add boilerplate text to a document by using the Word JavaScript API.</p>
                <br />
                <h3>Try it out</h3>
                <button id="Salutation">Insert Salutation</button>
                <button id="FirstName">Insert First Name</button>
                <button id="Lastname">Insert Last Name</button>
        </div>
    </body>
</html>

据我所知,我已经转到选项信任中心设置,并将托管我的文件的 https url 添加到受信任的目录 url。但是插件不可用,所以我假设我的代码在某处不正确。我还去掉了 home.js,所以它只初始化了办公室,但这也不起作用。

还有人知道是否可以使用新的 office-js api 插入合并字段?

【问题讨论】:

  • 当您有 2 个松散相关的问题时,通常最好针对 SO 提出 2 个单独的问题。
  • 我已将 home.js 更改为托管它的完全限定域名,该域名也具有 https。它仍然没有作为我的插件之一出现。我认为清单文件应该与 js 和 html 文件位于同一文件夹中是正确的?
  • 清单不需要与其他文件位于同一文件夹中。你能在浏览器中看到 home.html 吗?
  • 你的 url 应该是 home.html,而不是 home.js(虽然可能只是一个错字 :) 清单文件告诉 Office 去哪里找到你的应用程序 - 它不坐在您的 Web 服务器上,它由 Office 加载(如果您使用的是 Office 加载项模板,Visual Studio 会为您执行此操作;在生产中,这可能是通过 Office 商店或其他一些内部加载项的方法)跨度>

标签: office-js


【解决方案1】:

关于没有在 Word 中显示您的加载项,您需要更新 SourceLocation 以指向托管加载项的 URL。

关于你的第二个问题,我不知道你是否可以插入合并字段,但有办法bind to a text area。我建议你也看看这个样本,Word-Add-in-JavaScript-AddPopulateBindings

【讨论】:

    【解决方案2】:

    找不到“home.html”。这将需要一个完整的网址。您需要在 Web 服务器上运行 home.html(并且需要使用 https)。

    如果您使用的是 Visual Studio,我建议您使用 Office 加载项模板开始一个新项目并复制您的示例,它会为您设置一个以 ~ 开头的 URL,并被翻译成正确的内容正在构建中。

    如果您使用其他东西,here's the documentation,但您的网址将类似于 &lt;SourceLocation DefaultValue="https://localhost:8443/app/home/home.html"/&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-15
      • 1970-01-01
      • 2011-07-24
      • 1970-01-01
      • 2013-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多