export const exportCsv = (title: string, data: any[], needComma?: boolean) => {
let dataValue = [''];
if (needComma) {
dataValue = data.map(val => `${Array.isArray(val) ? val.map((valItem: string) => String(valItem)).join(',') : val}\n`);
} else {
dataValue = data.map(val => `${Array.isArray(val) ? val?.map((valItem: string) => String(valItem)?.replace(',', '')).join(',') : val?.replace(',', '')}\n`);
}
const blob = new Blob([`\uFEFF${dataValue.join('')}`], { type: 'text/csv;charset=gb2312;' });
const a = document.createElement('a');
a.download = `${title}.csv`;// 这里替换为你需要的文件名
a.href = URL.createObjectURL(blob);
a.click();
};
// 如下:
exportCsv('Validate Template', [
"We're going to validate your data from row 3, column 2 of the table",
['eg.', '323456'],
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'10',
]);
将数据导出为 CSV 格式
最新推荐文章于 2022-10-26 20:47:23 发布