I just want to create a new Word document from within Excel and make it available as an Office Script.
It sounds simple enough but I just cannot get it right.
I am beginning to think it’s not possible.
Ultimately I am getting Open_AI to analyze an Excel sheet and then create a report with the text returned, but just getting to create a “Hello world” Word Document is proving difficult.
What am I missing?
This is the script I am working with:
`// Import the WordScript module
import * as WordScript from “OfficeScript/word”;
// Create a new Word document and add text
async function main(workbook: ExcelScript.Workbook) {
// Create a new Word application object
let wordApp = new WordScript.WordApplication();
// Create a new Word document
let doc = await wordApp.createDocument();
// Add some text to the document
let paragraph = doc.addParagraph("Hello, World!");
// Apply bold formatting to the text
paragraph.font.bold = true;
// Save the document to the Documents folder
let documentsFolder = wordApp.getDocumentsFolder();
let filePath = documentsFolder + "\MyDocument.docx";
await doc.save(filePath);
}
`
I have tried a number of ways to create a Word document from within Excel using Office Script, but I just cannot access the Office object. What am I missing?