Files
transactions-list-parser/PriorBankParser/download_receipt.js
2023-07-23 17:10:20 +03:00

27 lines
885 B
JavaScript

function downloadCSVFile() {
const data = [...document.querySelectorAll(".k-grid-content table[role='grid'] tbody tr")]
.map(row => [...row.querySelectorAll("td, th")]
.map(col => col.innerText)
.reduce((a, b) =>
`${a},${b}`)).reduce((a, b) => `${a}\r\n${b}`);
let fileName = document.querySelector('.filter-text span').innerHTML
.replace('за период c ', 'receipts_')
.replace(' по ', '_')
.replaceAll('.', '-');
fileName = fileName + '.csv'
const csv_file = new Blob([data], {type: "text/csv"});
const download_link = document.createElement("a");
download_link.download = fileName;
download_link.href = window.URL.createObjectURL(csv_file);
download_link.style.display = "none";
document.body.appendChild(download_link);
download_link.click();
return fileName;
}