当前位置:网站首页>JS export JSON array to excel
JS export JSON array to excel
2022-07-18 21:40:00 【spring-java】
1、 Defined function
const jsonData = [
{
name:' A passer-by ',
phone:'123456789',
email:'[email protected]'
},
{
name:' Cannon fodder B ',
phone:'123456789',
email:'[email protected]'
},
{
name:' Bandit c ',
phone:'123456789',
email:'[email protected]'
},
{
name:' Rogue Ding ',
phone:'123456789',
email:'[email protected]'
},
];
/**
* export json The data is Excle form
* @param {json} data To export json data
* @param {String} head Header , Optional Parameter example :' name , mailbox , Telephone '
* @param {*} name Exported file name , Optional
*/
function jsonToExcel(data, head, name = ' Exported file name ') {
let str = head ? head + '\n' : '';
data.forEach(item => {
// Splicing json data , increase \t To prevent tables from displaying scientific notation or other formats
for(let key in item) {
str = `${str + item[key] + '\t'},`
}
str += '\n'
});
console.log(str)
// encodeURIComponent Solve the Chinese garbled code
const uri = 'data:text/csv;charset=utf-8,\ufeff' + encodeURIComponent(str);
// By creating a a Tag implementation
const link = document.createElement("a");
link.href = uri;
// Name the downloaded file
link.download = `${name + '.csv'}`;
link.click();
}
2、 call
jsonToExcel(jsonData, " full name , Telephone , mailbox ")
边栏推荐
- (笔记整理未完成)【图论:最小生成树】
- [Huang ah code] Why do I suggest you choose go instead of PHP?
- MySQL -- string function
- [C language brush leetcode] 1432 The maximum difference that can be obtained by changing an integer (m)
- Design and sharing of inclinometer based on single chip microcomputer
- Best practices for the use of exclusive resource pools - Introduction to the use of dependent services
- Sword finger offer 55 - ii balanced binary tree
- leetcode:1552. Magnetic force between two balls [maximum value of maximum value = two points]
- Introduction to sap appgyver
- MySQL - multi table query - relationship between tables
猜你喜欢

How to deal with the security risks of the third party in the supply chain

LeetCode+ 86 - 90 双指针、回溯、区间 dp 专题

Sword finger offer 55 - ii balanced binary tree

VMware recovery snapshot failed to create an anonymous paging file of 5040 MB: insufficient system resources to complete the requested service

Introduction to phabricator conduct API

基于单片机倾角检测仪设计分享

科技云报道:构建可观测性的核心能力是什么?

Configuration actuelle de freeswitch

Technology cloud report: what is the core ability to build observability?

Part 13: implementation of STM32 I2C serial bus communication
随机推荐
What is the event delegation in JS?
Mathematical modeling does not know latex typesetting | it teaches you how to use beautiful latex formulas gracefully in word
R language ggplot2 visualization: use the ggballoonplot function of ggpubr package to visualize faceted balloon graph (visualization of contingency table composed of two classification variables), fac
Best practices for exclusive resource pool use -notebook and training task linkage
Layoffs are coming
将一个文件夹中的内容复制到另一个文件夹中
专属资源池使用最佳实践-Notebook与训练任务联动
The University of Leuven recruited postdoctoral researchers to use ai/ml to analyze images of solar activity areas and predict flares
Calculate text similarity based on gensim
General Administration of market supervision: 15 batches of ice cream products such as Pudding Ice cream are unqualified
【我的OpenGL学习进阶之旅】NDK开发中find_library查找的系统动态库在哪里?
[dynamic programming]dp21 regular expression matching - difficult
MySQL -- string function
阿普奇 E8 工控机——MinipiceCAN卡在建筑机器人的应用
Spatial attribute overview C language
Based on servlet project -- blog system
Blog migration from cloudbase to virtual machine
Introduction to phabricator conduct API
AcWing 396. 矿场搭建 题解(tarjan割点)
Redis - detailed explanation of slot management commands