Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excel download is not working properly in Ipad pro 12.8 Safari(Sheetjs Community Edition) #2049

Closed
jyothishtj opened this issue Jul 6, 2020 · 1 comment

Comments

@jyothishtj
Copy link

Hi Team,
I am trying to use the sheetjs for making the excel download from client side. The download is working fine in chrome and firefox. But, when trying to run the download from Safari (Ipad pro 12.8) it is giving error like "Safari can not open the page. The error was the operation can not be completed. The error was "Webkitblob resource error 1". I was intially using the code

`function Workbook() {
if (!(this instanceof Workbook)) {
return new Workbook();
} else {
this.SheetNames = [];
this.Sheets = {};
return true;
}
}

export const download = (url, name) => {
const a = document.createElement('a');
a.href = url;
a.download = name;
a.click();
window.URL.revokeObjectURL(url);
};

function s2ab(s) {
const buf = new ArrayBuffer(s.length);
const view = new Uint8Array(buf);
for (let i = 0; i !== s.length; ++i) {
view[i] = s.charCodeAt(i) & 0xff;
}
return buf;
}

// This function is used for crerating the excel sheet based of the data array and excel name. This is the using the sheetJs(xlsx) npm module
const exportToExcel = (data, ExcelName) => {
import('xlsx').then(XLSX => {
const wb = new Workbook();
const ws = XLSX.utils.json_to_sheet(data);
wb.SheetNames.push('sheet');
wb.Sheets['sheet'] = ws;
const wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: true, type: 'binary'});
const url = window.URL.createObjectURL(new Blob([s2ab(wbout)], {type: 'application/octet-stream'}));
download(url, ${ExcelName}.xlsx);
});
};
export default exportToExcel;`.

Then as mentioned in the post https://stackoverflow.com/questions/54339607/mobile-safari-download-issue-the-operation-couldn-t-be-completed-webkitblobr i tried to include a timeout for the revokeObjectURL.

export const download = (url, name) => { const a = document.createElement('a'); a.href = url; a.download = name; a.click(); setTimeout(() => { window.URL.revokeObjectURL(url); }, 1000); };

But, now getting the file as "Unknown". Can you please suggest the safari is currently supported and how the download issue can be fixed?

@SheetJSDev
Copy link
Contributor

iOS downloads are notoriously tricky. You can try changing the MIME type to application/vnd.ms-excel:

const url = window.URL.createObjectURL(new Blob([s2ab(wbout)], {type: 'application/vnd.ms-excel'}));

But overall there are known issues with iOS Safari eligrey/FileSaver.js#12 is a great summary of the problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants