CSV 不支持导出 0.0 bug All In One

CSV 不支持导出 0.0 bug All In One

[
	{
	    "Column 1": "0.0"
	},
	{
	    "Column 1": "2-1"
	},
	{
	    "Column 1": 0.0
	}
]

CSV 导出不支持 0.0,只能展示 0

    getCSVData (columns, rows) {
        const keys = columns.map(obj => obj.key);
        const result = [];
        rows.forEach((obj, i) => {
            const arr = [];
            keys.forEach(key => {
                let value = obj[key];
                if (obj[key] !== null) {
                    const format = columns.find(item => item.key === key)?.format;
                    //trend 行是偶数行,且排除 title 列
                    if(key !== 'ua_group_name') {
                        value = Utils.formats(value, (i + 1) % 2 === 0 ? 'TDF200P' : format);
                    }
                } else {
                    // value = '-';
                }
                arr.push(value);
                // arr.push(0.0);
                // arr.push('0.0');
            });
            result.push(arr);
        });
        console.log('rows', rows);
        console.log('result', result);
        return result;
    },

refs

https://www.papaparse.com/demo



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 ️,侵权必究⚠️!


原文地址:https://www.cnblogs.com/xgqfrms/p/15823530.html