It is necessary to export it to .csv (or to any other format that an exel could open without problems). Preferably without using third-party libraries.
1 answer
Create an array of strings in which the field values of the objects are separated
;or,1 (and with the addition of each line terminating\r\n).
2 if necessary, enclose the value in double quotesCreate an instance of Blob by passing the generated array to the constructor and entering
text/csvin thetypeparameter string (MIME type)Get the URL of a Blob instance with the static
URL.createObjectURL()methodDo whatever you want with the URL.
1 Excel uses a comma as a delimiter.
2 In the case when the value is a string, and contains characters separator or newline. If the value also contains quotes, then they must be doubled: "qwe ""rty"" uio" - this can be done using the String.replace() method.
let data = rndObjArr(50), csvRows = [], blob; data.forEach(o => csvRows.push(`${o.date},${o.count}\r\n`)); blob = new Blob(csvRows, { type: 'text/csv;charset=utf-8;' }); document.body.insertAdjacentHTML('beforeend', ` <a href="${URL.createObjectURL(blob)}" download="export.csv">Скачать CSV</a> `); function rndObjArr(size) { const rndInt = (from, to) => Math.floor(Math.random() * (to - from)) + from; let result = [], dateStr; while (size--) { dateStr = `${rndInt(2010, 2019)}-${String(rndInt(1, 13)).padStart(2, '0')}-${String(rndInt(1, 31)).padStart(2, '0')}`; result.push({ date: dateStr, count: rndInt(0, 50) }); } return result; } 
;and\nwhat exactly is the problem? - Artem Gorlachev;in your data! - Stepan Kasyanenko