我的代码
import { ExportToCsv } from 'export-to-csv';
var data = [
{
name: 'Test 1',
age: 13,
average: 8.2,
score: '3-1',
approved: true,
description: "using 'Content here, content here' "
},
{
name: 'Test 2',
age: 11,
average: 8.2,
score: '2-1',
approved: true,
description: "using 'Content here, content here' "
},
{
name: 'Test 4',
age: 10,
average: 8.2,
score: '3-1',
approved: true,
description: "using 'Content here, content here' "
},
];
const options = {
fieldSeparator: ',',
quoteStrings: '"',
decimalSeparator: '.',
showLabels: true,
showTitle: true,
title: 'My Awesome CSV',
useTextFile: false,
useBom: true,
useKeysAsHeaders: true,
// headers: ['Column 1', 'Column 2', etc...] <-- Won't work with useKeysAsHeaders present!
};
const csvExporter = new ExportToCsv(options);
csvExporter.generateCsv(data);Angular:导出为CSV时出现问题,值为'-‘的字段在导出为csv分数(’3-1‘,'2-1',..)时出现转换为日期的问题转换为日期的值,如(01-Mar,01-Feb,...)。如何解决这个问题。请帮帮忙
发布于 2021-01-08 13:23:51
使用文本编辑器(如记事本)打开csv文件,并验证破折号内容是否正确。
当您说它将它们转换为日期时,我假设您正在使用Excel打开csv文件?如果是这种情况,请尝试选择所有值并将格式更改为文本以查看实际值。Excel自动格式设置很可能是问题所在,而不是文件本身。
CSV或逗号分隔值仅指格式化。
https://stackoverflow.com/questions/65623711
复制相似问题