-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathtoCSV.js
More file actions
52 lines (51 loc) · 1.29 KB
/
toCSV.js
File metadata and controls
52 lines (51 loc) · 1.29 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
(function(){
var separator = ",",
getText = function(cell){
var html = "";
if(cell.hasAttribute("data-two-diagonals")){
html = table.getHTML(cell, 0) + " " + table.getHTML(cell, 1) + "<br>" + table.getHTML(cell, 2);
}
else if(cell.hasAttribute("data-diagonal")){
html = table.getHTML(cell, 0) + "<br>" + table.getHTML(cell, 1);
}
else{
html = table.getHTML(cell);
}
var text = html.replace(/<\s*br\s*\/?\s*>/gi, "\n").replace(/<[^>]+?>/g,"").replace(/\&(lt|gt|amp|quot);?/gi, function(total, name){
if(name == "lt"){ return "<" }
if(name == "gt"){ return ">" }
if(name == "amp"){ return "&" }
if(name == "quot"){ return "quot" }
});
if(/[\n"]/.test(text) || text.indexOf(separator)>-1){
text = '"'+text.replace(/"/,"\\\"")+'"';
}
return text;
},
getTextn = function(cell, n){
}
table.createInterpreter("csv", function(){
var matrix = this.Table.matrix(),
str = "";
separator = document.getElementById('opt-csv-separator').value;
if(separator == "tab"){
separator = "\t";
}
for(var i=0;i<matrix.length;i++){
var row = matrix[i];
if(i>0){
str += "\n";
}
for(var j=0;j<row.length;j++){
var cell = row[j];
if(j>0){
str += separator;
}
if(cell.cell){
str += getText(cell.cell);
}
}
}
return str;
})
})();