我已经成功地将数据导出为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".
}
}
在此先感谢您的帮助和建议。
相关分类