הקוד קצת מסורבל וטיפונת שגוי, אז שיפרתי אותו:
function exportToCSV() {
const rows = [...document.querySelectorAll('#table-report-sales tr')];
const singleRow = (e) => [...e.querySelectorAll('th, td')].map(x => x.innerText).join(',');
const csvContent = '\uFEFF' + rows.map(singleRow).join('\n');
const link = document.createElement("a");
link.setAttribute("href", 'data:text/csv; charset=utf-8,' + encodeURI(csvContent));
link.setAttribute("download", "sales_report.csv");
document.body.appendChild(link);
link.click();
}