Created
July 20, 2022 08:50
-
-
Save xuruiyao-msft/e8034627aa08a75d1903bfa6564e349c to your computer and use it in GitHub Desktop.
This sample shows how to get and set the change tracking mode and get the before and after of reviewed text.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: SettingTest | |
description: >- | |
This sample shows how to get and set the change tracking mode and get the | |
before and after of reviewed text. | |
host: WORD | |
api_set: {} | |
script: | |
content: "$(\"#run\").click(() => tryCatch(run));\n\nasync function run() {\n await Word.run(async (context) => {\n //\_Queue\_commands\_add\_a\_setting.\n var settings = context.document.settings;\n var startMonth = settings.add(\"startMonth\", { month: \"March\", year: 1998 });\n var address = settings.add(\"country\", \"china\");\n\n //\_Queue\_a\_command\_to\_get\_the\_count\_of\_settings.\n var count = settings.getCount();\n\n //\_Synchronize\_the\_document\_state\_by\_executing\_the\_queued\_commands,\n //\_and\_return\_a\_promise\_to\_indicate\_task\_completion.\n await context.sync();\n console.log(\"current count: \" + count.value);\n\n //\_Queue\_a\_command\_to\_delete\_the\_setting.\n startMonth.delete();\n\n //\_Queue\_a\_command\_to\_get\_the\_new\_count\_of\_settings.\n count = settings.getCount();\n\n //\_Synchronize\_the\_document\_state\_by\_executing\_the\_queued\_commands,\n //\_and\_return\_a\_promise\_to\_indicate\_task\_completion.\n await context.sync();\n console.log(\"after deletion the count is: \" + count.value);\n\n let countrySettingGetItem = settings.getItem(\"country\");\n countrySettingGetItem.load();\n await context.sync();\n console.log(\"countrySettingGetItem key: \" + countrySettingGetItem.key);\n console.log(\"countrySettingGetItem value: \" + countrySettingGetItem.value);\n\n let getItemOrNull = settings.getItemOrNullObject(\"country\");\n getItemOrNull.load();\n await context.sync();\n console.log(\"getItemOrNull key: \" + getItemOrNull.key);\n console.log(\"getItemOrNull value: \" + getItemOrNull.value);\n\n //why?\n settings.load();\n await context.sync();\n console.log(\"settings items length: \" + settings.items.length);\n\n let settingItem1 = settings.items[0];\n settingItem1.load();\n await context.sync();\n console.log(\"keyItem1: \" + settingItem1.key);\n console.log(\"valueItem1: \" + settingItem1.value);\n\n let getNull = settings.getItemOrNullObject(\"hahah\");\n getNull.load();\n await context.sync();\n if (getNull.isNullObject) {\n console.log(\"No such setting.\");\n }\n console.log(\"getNull key:\" + getNull.key);\n console.log(\"getNull value:\" + getNull.value);\n });\n}\n\n/**\_Default\_helper\_for\_invoking\_an\_action\_and\_handling\_errors.\_*/\nasync function tryCatch(callback) {\n try {\n await callback();\n } catch (error) {\n //\_Note:\_In\_a\_production\_add-in,\_you'd\_want\_to\_notify\_the\_user\_through\_your\_add-in's\_UI.\n console.error(error);\n }\n}\n" | |
language: typescript | |
template: | |
content: |- | |
<button id="run" class="ms-Button"> | |
<span class="ms-Button-label">run</span> | |
</button> | |
language: html | |
style: | |
content: |- | |
section.samples { | |
margin-top: 20px; | |
} | |
section.samples .ms-Button, section.setup .ms-Button { | |
display: block; | |
margin-bottom: 5px; | |
margin-left: 20px; | |
min-width: 80px; | |
} | |
language: css | |
libraries: | | |
https://appsforoffice.microsoft.com/lib/beta/hosted/office.js | |
@types/office-js | |
office-ui-fabric-js@1.4.0/dist/css/fabric.min.css | |
office-ui-fabric-js@1.4.0/dist/css/fabric.components.min.css | |
core-js@2.4.1/client/core.min.js | |
@types/core-js | |
jquery@3.1.1 | |
@types/jquery@3.3.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment