GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — JavaScript/ExportToCsvBasic.js at master · Sludovic/JavaScript

Expand file tree

/

ExportToCsvBasic.js

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
34 lines (33 loc) · 1.29 KB
/

ExportToCsvBasic.js

Copy path

File metadata and controls

34 lines (33 loc) · 1.29 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
* Adapté de la réponse sur stackoverflow.com - http://stackoverflow.com/a/14966131
* link = element html 'a' dans la page
* JSONdata = données du tableau en JSON
* KEYSdata = corresponds au nom des colonnes dans le JSON.
* HeaderData = corresponds au nom des colonnes que l'on veut à l'affichage dans le meme ordre que les colonnes sql.
* Peut être généré automatiquement
* KEYSdata et HeaderData doivent être correspondants
* name = nom du fichier csv (ex: blabla.csv)
*/
function exportToCsv(link,JSONdata,KEYSdata,name,HeaderData) {
var data = eval(JSONdata);
var str;
var orderedData = [];
for(var i = 0; i < data.length; i++) {
if(i == 0){
if(HeaderData!= null){
orderedData.push(HeaderData.join(','));
}else{
KEYSdata = Object.keys(data[i]);
orderedData.push(KEYSdata.join(','));
}
}
var liste = [];
for(var j = 0; j < KEYSdata.length; j++) {
liste.push(data[i][KEYSdata[j]]);
}
orderedData.push(liste.join(','));
}
var csvContent = "data:application/vnd.ms-excel,charset=utf-8,\r\n" + orderedData.join("\r\n");
link.setAttribute("download",name);
link.setAttribute("href", encodeURI(csvContent));
}
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.