json to xlsx

Solutions on MaxInterview for json to xlsx by the best coders in the world

showing results for - "json to xlsx"
Vincent
02 Aug 2020
1// Import XLSX CDN
2<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.min.js" 
3	integrity="sha512-WaHZ16+n6qSSVxDii8MZGmFlnro3iZdJa/hb1XKraoMx1/HVILhLdAX22ypk4lT/8+t4XMYcjzCDwfvZ1CAJgw==" 
4	crossorigin="anonymous" 
5	referrerpolicy="no-referrer">
6</script>
7
8// File Saver
9<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.0/FileSaver.min.js" 
10integrity="sha512-csNcFYJniKjJxRWRV1R7fvnXrycHP6qDR21mgz1ZP55xY5d+aHLfo9/FcGDQLfn2IfngbAHd8LdfsagcCqgTcQ==" 
11crossorigin="anonymous" referrerpolicy="no-referrer"></script>
12
13/////
14const worksheet = XLSX.utils.json_to_sheet(data);
15const EXCEL_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8';
16
17const workbook = {
18    Sheets: {
19        'data': worksheet
20    },
21    SheetNames: ['data']
22};
23
24const buffer = XLSX.write(wokbook, { bookType: 'xlsx', type: 'array' });
25
26const file = new Blob([buffer], { type: EXCEL_TYPE });
27saveAs(file, 'example.xslx');