Is it possible to set a word documents custom prop

2019-09-12 06:57发布

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!

2条回答
看我几分像从前
2楼-- · 2019-09-12 07:14

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).

查看更多
Summer. ? 凉城
3楼-- · 2019-09-12 07:20

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.

查看更多
登录 后发表回答