RPAOffice
Word
Word
The Word module is responsible for performing handling actions on files created in Word. Its methods can be accessed as in the example below:
js
const fillError = await Office.Word.fillWordTemplate["v2_0_0"]({
outputPath: "C:/Users/Roberty/Documents/",
fileName: "teste.docx",
templatePath: "C:/Users/Roberty/Documents/testeTemplate.docx",
data: {
name: "Roberty",
phone: "123-456-7890",
email: "roberty@roberty.app"
}
})
Methods
fillWordTemplate
Method responsible for filling in the variables of a dynamic Word template.
js
const fillError = await Office.Word.fillWordTemplate["v2_0_0"]({
outputPath: "C:/Users/Roberty/Documents/",
fileName: "teste.docx",
templatePath: "C:/Users/Roberty/Documents/testeTemplate.docx",
data: {
name: "Roberty",
phone: "123-456-7890",
email: "roberty@roberty.app"
}
})
Required parameters
outputPath: String - expects the path of the folder where the filled file will be saved.fileName: String - expects the name (with extension) of the file that will be generated. If a file with that name already exists in the folder, the method returns theoutputAlreadyExistserror.templatePath: String - expects the path of the template that will be filled in. The path must contain the file name and the extension.
Optional parameters
data: Object - expects an object with the variables that will be filled in the template. The object keys must be the names of the template variables defined between double braces (e.g.{{name}}).
Return
The constant or variable created, such as the fillError of the example shown earlier, receives a value of the Object type that gives access to the following properties:
fillError.error: String - returns an error message if the filling is not performed successfully (e.g.templateNotFoundwhen the template is not found,outputAlreadyExistswhen the output file already exists). When the filling succeeds, the returned object is empty.