Furya
Furya

Reputation: 309

Word addin insert template from local path

I would like to insert template from local path to word with an addin. I look at the code provide by microsoft : https://github.com/OfficeDev/Office-Add-in-samples/tree/main/Samples/word-import-template

It works greats, however I would like to do the same thing with a button that use a local document.

I tried to use new File but it doesn't work :

    // Gets the contents of the selected file.
async function getFileContents() {
//const myTemplate = document.getElementById("template-file");
const file = new File(["Trame"], "Trame.docx");
const reader = new FileReader();
reader.onload = (event) => {
    // Remove the metadata before the Base64-encoded string.
    const startIndex = reader.result.toString().indexOf("base64,");
    template = reader.result.toString().substring(startIndex + 7);

    // Import the template into the document.
    importTemplate();

    // Show the Update section.
    $("#imported-section").show();
};

// Read the file as a data URL so we can parse the Base64-encoded string.
reader.readAsDataURL(file);
}

Any ideas how to do the same thing without the selector ? My word document is in the same folder as taskpane.html

Thanks

Upvotes: 0

Views: 22

Answers (0)

Related Questions