使用JavaScript API添加合并字段

时间:2019-01-19 13:50:52

标签: ms-word office-js office-addins word-addins word-field

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

1 个答案:

答案 0 :(得分:1)

   `$customBBCodes = $this->getVar('comments-form-custombbcodes');
    if(is_array($customBBCodes)){
        if (count($customBBCodes)) {
            foreach($customBBCodes as $code) {
                if ($code->button_enabled) {
                    $k = 'custombbcode' . $code->id;
                    $title = trim(JCommentsText::jsEscape($code->button_title));
                    $text = empty($code->button_prompt) ? JText::_('BBCODE_HINT_ENTER_TEXT') : JText::_($code->button_prompt);
                    $open_tag = $code->button_open_tag;
                    $close_tag = $code->button_close_tag;
                    $icon = $code->button_image;
                    $css = $code->button_css;`                    

上方是“合并字段”的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>