Downloading a file or creating a workbook with new data using Excel api

Mike Young 0 Reputation points
2023-10-24T18:45:46.96+00:00

We have created a plugin for Excel that uses the Javascript Api (in typescript). We would like to allow the user to download a file that has some report data. The following code works in our plug in when we run excel in chrome, but not in the excel app on the mac.

    const file = new File(["foo"], "new-note.txt", {
      type: "text/plain",
    });
    const link = document.createElement("a");
    const url = URL.createObjectURL(file);

    link.href = url;
    link.download = file.name;
    document.body.appendChild(link);
    link.click();

    document.body.removeChild(link);
    window.URL.revokeObjectURL(url);

I know this is due to an issue with downloading a file in safari. Is there a way to do this using the Excel api?

Alternatively, we could create a new workbook with that data. But the examples for Excel.createWorkbook all involve using data from an existing workbook. Is there a way to use Excel.createWorkbook to create a workbook populated with new data, or to set values in the newly created workbook? Thanks!

Microsoft 365 and Office Development Office JavaScript API
Microsoft 365 and Office Excel For business Windows
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.