Table cols to raws
Convert table columns to raws by comma
by Weron2
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Table2cols converter</title>
<script>
function makestring() {
let tab = RegExp("\\t","g");
let newline = RegExp("\n","g");
let lines = document.getElementById('rawtext').value.split(newline);
let columns = [];
for (let i=0;i<lines.length;i++){
let cols = lines[i].split(tab);
if (i==lines.length-1) {
for (let j=0;j<cols.length;j++) {
columns[j]= columns[j] + cols[j];
}
}
else {
for (let j=0;j<cols.length;j++) {
columns[j] = (i==0) ? cols[j] + ',': columns[j] + cols[j] +','; //to avoid undefined in first place
}
}
}
//console.log(columns);
let resultStr = '';
for (let k=0;k<columns.length;k++) {
resultStr = resultStr + columns[k] + '\n\n';
}
document.getElementById('result').value = resultStr;
}
function download(filename, text) {
var pom = document.createElement('a');
pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + (text));
pom.setAttribute('download', filename);
if(document.createEvent) {
var event = document.createEvent('MouseEvents');
event.initEvent('click', true, true);
pom.dispatchEvent(event);
} else {
pom.click();
}
}
</script>
</head>
<body>
<textarea rows='10' cols='125' id='rawtext'></textarea><br>
<input type='button' onclick='makestring()' value='Make String'><br>
<textarea rows='30' cols='200' id='result'></textarea><br>
<input type="button" onclick="download('table.txt', document.getElementById('result').value.replace(/\n/g, '\r\n'));" value="Download">
</body>
</html>