我目前正在使用RQL(资源查询语言),现在我想将包含约40.000行的整个表导出到CSV文件中。
我的脚本如下:
public async exportCSV() {
let queryCSV = "?q=";
queryCSV += this.getRQLSelect();
this.loading = true;
const headers = new HttpHeaders({'Accept': 'application/csv'});
await this.http.get(this.path + queryCSV, {
headers: headers,
responseType: "text",
observe: 'response'
}).toPromise().then(res => {
const blob = new Blob(['\ufeff' + res.body], {type: 'text/csv;charset=utf-8;'});
const downlaodLink= document.createElement("a");
const url = URL.createObjectURL(blob);
const isSafariBrowser = navigator.userAgent.indexOf('Safari') !== -1 && navigator.userAgent.indexOf('Chrome') === -1;
if (isSafariBrowser) { //if Safari open in new window to save file with random filename.
downlaodLink.setAttribute("target", "_blank");
}
downlaodLink.setAttribute("href", url);
downlaodLink.setAttribute("download", "File.csv");
downlaodLink.style.visibility = "hidden";
document.body.appendChild(downloadLink);
downlaodLink.click();
document.body.removeChild(downlaodLink);
});
this.loading = false;
}
例如,如果我将查询限制设置为50行,则一切正常,但是如果我尝试导出整个结果集,则浏览器窗口将冻结。
如何在不使浏览器崩溃的情况下导出整个数据表?