Is it possible to set a word documents custom properties?

左心房为你撑大大i 提交于 2019-12-13 21:28:32

问题


So basically i want to add some custom properties to a word document.

Is this possible yet from the word api 1.3?

I found something along the lines of:

context.document.workbook.properties

but that only seems to work for excel.

Thanks!


回答1:


To add more detail to the previous answer: Yes Word.js 1.3 introduces creation and retrieval of custom and built-in document properties. The API is still in preview, you need to at least have the December fork build for this feature to work. Make sure you try it on 16.0.7766+ builds. Also please make sure to use our Preview CDN for Office.js https://appsforoffice.microsoft.com/lib/beta/hosted/office.js

Here is a code sample on how to create a custom property in Word:

 function createCustomProperty(){
        Word.run(function (context) {
          //method accepts property name plus value
            context.document.properties.customProperties.add("property_name", 123);
            return context.sync()
            .catch(function (e) {
                console.log(e.message);

            })

        })

    }

Check out the documentation to see other functionalities, including getting built-in properties https://github.com/OfficeDev/office-js-docs/blob/WordJs_1.3_Openspec/reference/word/documentproperties.md

Hope this helps, Thanks! Juan.




回答2:


Word API 1.3 introduces documentProperties and customProperty, but the status is still listed as Preview, and requires Word 2016 Desktop Version 1605 (Build 6925.1000) or later or the mobile apps (not yet available online).



来源:https://stackoverflow.com/questions/41802181/is-it-possible-to-set-a-word-documents-custom-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!