Ms word 使用JavaScript API添加合并字段

Ms word 使用JavaScript API添加合并字段,ms-word,office-js,office-addins,word-addins,word-field,Ms Word,Office Js,Office Addins,Word Addins,Word Field,我想将JavaScript API中的合并字段()插入到单词表中。但是,我找不到Office Word加载项的JavaScript API。以前已经有人问过可能的重复:例如。您可能希望对UserVoice的建议进行投票:@Cindymister我尝试了此链接,但此xml出现错误。有没有其他xml用于合并字段,我可以试试看?如果没有看到您的代码,就不可能知道/说。请注意,链接中的答案不是针对合并字段,而是一种“模式”,用于说明如何使用开放式XML(平面文件OPC格式)插入字段。它可能会帮助您创建一

我想将JavaScript API中的合并字段(
)插入到单词表中。但是,我找不到Office Word加载项的JavaScript API。

以前已经有人问过可能的重复:例如。您可能希望对UserVoice的建议进行投票:@Cindymister我尝试了此链接,但此xml出现错误。有没有其他xml用于合并字段,我可以试试看?如果没有看到您的代码,就不可能知道/说。请注意,链接中的答案不是针对合并字段,而是一种“模式”,用于说明如何使用开放式XML(平面文件OPC格式)插入字段。它可能会帮助您创建一个包含示例合并字段的非常简单的文档。保存并关闭。使用OpenXMLSDK生产力工具打开文档并检查字段的底层XML。将其与链接答案中的代码进行比较,以了解其区别/需要如何根据您的目的进行调整。您可能还会发现这一点很有用:
<?xml version=\"1.0\" standalone=\"yes\"?> <?mso-application progid=\"Word.Document\"?><pkg:package xmlns:pkg=\"http://schemas.microsoft.com/office/2006/xmlPackage\"><pkg:part pkg:name=\"/_rels/.rels\" pkg:contentType=\"application/vnd.openxmlformats-package.relationships+xml\" pkg:padding=\"512\"><pkg:xmlData><Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\"> <Relationship Id=\"rId1\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument\" Target=\"word/document.xml\"/> </Relationships></pkg:xmlData> </pkg:part> <pkg:part pkg:name=\"/word/document.xml\" pkg:contentType=\"application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml\"><pkg:xmlData><w:document  xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:body>    <w:p w:rsidR=\"002715FD\" w:rsidRDefault=\"002715FD\"><w:fldSimple w:instr=\" MERGEFIELD &quot;Last_Name&quot; \"><w:r><w:rPr><w:noProof /></w:rPr><w:t>«Last_Name»</w:t></w:r></w:fldSimple></w:p><w:sectPr w:rsidR=\"00000000\"> <w:pgSz w:w=\"12240\" w:h=\"15840\"/><w:pgMar w:top=\"1440\" w:right=\"1440\" w:bottom=\"1440\" w:left=\"1440\" w:header=\"720\" w:footer=\"720\" w:gutter=\"0\"/><w:cols w:space=\"720\"/></w:sectPr> </w:body>  </w:document> </pkg:xmlData></pkg:part></pkg:package>  
Word.run(function (context) {

    // Queue a command to get the current selection and then
    // create a proxy range object with the results.
    var range = context.document.getSelection();

    // Queue a commmand to insert OOXML in to the beginning of the range.
    range.insertOoxml("PASTE ABOVE MERGE XML", Word.InsertLocation.start);

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    return context.sync().then(function () {
        console.log('OOXML added to the beginning of the range.');
    });
})
.catch(function (error) {
    console.log('Error: ' +JSON.stringify(error));
    if (error instanceof OfficeExtension.Error) {
        console.log('Debug info: ' + JSON.stringify(error.debugInfo));
    }
});