我已经成功地将我的数据导出为csv,这很有效,直到有一个#
字符搞砸了导出。它在#
之后停止了出口。当我打开文件时,我可以看到它正在提供换行符然后停止。
我已经在文本字段中添加了引用,因为需要导出,
等符号才能正常工作。
有人可以给我一些建议,为什么会见#
会给出这样的反应和解决方法吗?
删除#
是最不可思议的选择,真的更愿意保持#
我试图取代#
ascii \u0023
,这让我没有运气
我如何得到文本
const getDiv = bodyCellLabelClass.querySelectorAll('div');
const innerTxt = getDiv[ 0 ].innerText;
result.push(`"${innerTxt}"`);
result
的样本看起来像我console.log
[""$41.67"", ""9/9/2018"", ""10/9/2018"", ""9/9/2018"", ""#111"", ""3/11/2019""]
[""$41.67"", ""9/9/2018"", ""10/9/2018"", ""9/9/2018"", ""3"", ""3/11/2019""]
但是当我打开csv它看起来就像
$41.67, 9/9/2018, 10/9/2018, 9/9/2018, '↵'
没什么
这就是导出csv的样子
export class ExportUtil {
// export file, default excel
public static spreadsheet( rows, full_filename = 'test.xls' ): any {
let content = `data:application/vnd.ms-excel;charset=utf-8;`;
rows.forEach(function ( rowArray ) {
const row = rowArray.join(',');
content += row + '\r\n';
});
console.log(content, 'inside spreadsheet content');
const encodedUri = encodeURI(content);
const link = document.createElement('a');
link.setAttribute('href', encodedUri);
link.setAttribute('download', `${full_filename}`);
document.body.appendChild(link); // Required for FF
link.click(); // This will download the data file named "my_data.csv".
}
}
提前感谢您的任何帮助和建议。
尝试使用Blob
export class ExportUtil {
// export file, default excel
public static spreadsheet( rows, full_filename = 'test.xls' ): any {
let content = '';
rows.forEach(function ( rowArray ) {
const row = rowArray.join(',');
content += row + '\r\n';
});
console.log(content, 'inside spreadsheet content');
const blob = new Blob([ content ], { type: 'application/vnd.ms-excel;charset=utf-8;' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.setAttribute('href', url);
link.setAttribute('download', `${full_filename}`);
document.body.appendChild(link); // Required for FF
link.click(); // This will download the data file named "my_data.csv".
}
}