跳到主要内容

changeParagraphStyle

This function modifies the visual style of the specified paragraph.

Prompts

  • Change the style of paragraph 2 to Heading 1

Function registration

let func = new RegisteredFunction();
func.name = "changeParagraphStyle";
func.params = [
"parNumber (number): the paragraph number to apply style changes to",
"style (string): the style name to apply to the paragraph"
];

func.examples = [
"If you need to change the style of paragraph 3 to Heading 1, respond with:" +
"[functionCalling (changeParagraphStyle)]: {\"parNumber\": 3, \"style\": \"Heading 1\"}"
];

Parameters

NameTypeExampleDescription
parNumbernumber3The number of the paragraph to apply style changes to.
stylestring"Heading 1"The style name to apply to the paragraph.

Function execution

func.call = async function(params) {
Asc.scope.parNumber = params.parNumber;
Asc.scope.styleName = params.style;
await Asc.Editor.callCommand(function(){
let doc = Api.GetDocument();
let par = doc.GetElement(Asc.scope.parNumber - 1);
if (!par)
return;

let style = doc.GetStyle(Asc.scope.styleName);
par.SetStyle(style);
});
};

return func;

Methods used: GetDocument, GetElement, GetStyle, SetStyle, Asc.scope object

Result

changeParagraphStyle changeParagraphStyle