1
word JavaScript API를 사용하여 필드 코드를 추가하고 싶습니다. API documentation을 확인했지만 이것에 대해서는 아무 것도 발견하지 못했습니다. 이 API에서이 작업을 수행 할 수있는 방법이 있습니까?word javascript api를 사용하여 Word 용 필드 코드를 추가하는 방법
word JavaScript API를 사용하여 필드 코드를 추가하고 싶습니다. API documentation을 확인했지만 이것에 대해서는 아무 것도 발견하지 못했습니다. 이 API에서이 작업을 수행 할 수있는 방법이 있습니까?word javascript api를 사용하여 Word 용 필드 코드를 추가하는 방법
필드를 추가하기위한 API에는 직접적인 지원이 없습니다. 즉, 필드가 포함 된 Open XML을 만들어야합니다. 그런 다음이 Open XML을 문서에 삽입 할 수 있습니다 (다음 테스트되지 않은 코드 스 니펫의 일부).
// Run a batch operation against the Word object model.
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("<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="00000000" w:rsidRDefault="0043114D">
<w:r>
<w:fldChar w:fldCharType="begin"/>
</w:r>
<w:r>
<w:instrText xml:space="preserve"> PAGE \* Arabic \* MERGEFORMAT </w:instrText>
</w:r>
<w:r>
<w:fldChar w:fldCharType="separate"/>
</w:r>
<w:r>
<w:rPr>
<w:noProof/>
</w:rPr>
<w:t>1</w:t>
</w:r>
<w:r>
<w:fldChar w:fldCharType="end"/>
</w:r>
</w:p>
</w:body>
</w:document>
</pkg:xmlData>
</pkg:part>
</pkg:package>", 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));
}
});
위의 코드 조각을 테스트했지만 아무 것도 얻지 못했습니다. 너는 어떤 생각을 가지고 있니? –