Can't download file in macOS Safari Excel add-in

ВЭД Экономисты 0 Reputation points
2023-03-14T04:33:50.3133333+00:00

So, I'm developing an Excel add-in in macOS. I'm trying to create a file and download it then in browser. Here is the code (I'm using saveAs function from file-saver package):

async function saveFile(workbook: ExcelJS.Workbook, id) {
    const xls64 = await workbook.xlsx.writeBuffer();
    const blob = new Blob([xls64], { type: 'application/xlsx' });
    saveAs(blob, `${id}.xlsx`);
}

Also, I was trying to download file by this way:

function download(url, filename) {
fetch(url)
    .then((response) => response.blob())
    .then((blob) => {
        const link = document.createElement('a');
        link.href = URL.createObjectURL(blob);
        link.download = filename;
        link.click();
        console.log(link);
    })
    .catch(console.error);
 }

But it doesn't work as well. Type of file doesn't matter also.

In Edge (Windows add-in version) it works, while in Safari (macOS add-in) it doesn't... Also, I can download files when I open localhost in Safari browser outside the add-in. I see no errors in logs.

Could you help me out how to write code to download file in macOS add-in?

Excel
Excel
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
1,591 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,632 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Emily Hua-MSFT 27,556 Reputation points
    2023-03-14T08:06:14.0566667+00:00

    Hi @ВЭД Экономисты

    Welcome to Q&A forum~

    As your issue is related to Excel add-ins, to help you better, I would suggest you post new threads on other forums of following link.

    Excel add-ins developer community

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    0 comments No comments