How to use document.importStylesFromJson to import a style with space or dash in the name.

David Chrudimsky 5 Reputation points
2024-01-14T01:26:08.3933333+00:00

I'm attempting to use the document.importStylesFromJson(jsonstring) method to create styles in an existing document. I've figure out that for each style in the jsonstring, a nameLocal object needs to be specified as the name of the style. However, this name seems to be more restrictive than the name that can be provided using the Word GUI. As an example, if nameLocal is given a string with spaces or dashes (underscores work!), the method fails to create the desired style in the document. As an example, the following json string will produce a style in the document named teststyle3, but will completely ignore the creation of teststyle 4.

{"teststyle3":{"baseStyle":"Default Paragraph Font", "quickStyle":true,"nameLocal":"teststyle3", "priority":4, "type":"Character", "font":{"bold":false, "color":"#00ff00"}}, "teststyle4":{"baseStyle":"Default Paragraph Font", "quickStyle":true, "priority":4, "nameLocal":"teststyle 4", "type":"Character", "font":{"bold":false, "color":"#00ff00"}}}

If I remove the space from "nameLocal":"teststyle 4", then a style named teststyle4 will also be produced. Is there any way to specify style names with spaces or dashes? Is there a more complete set of documentation about document.importStylesFromJson() available? Thanks! David Chrudimsky

Word
Word
A family of Microsoft word processing software products for creating web, email, and print documents.
663 questions
JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
870 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,501 questions
{count} vote