How To Write Csv File Using Javascript?
I am creating one array dynamically.Following array is one example. textarray = [['label first','details of label 1'],['label sec','details of label 2'],['label 3','details of labe
Solution 1:
**Use this:**
<html>
<script type="text/javascript">
function createCSV() {
csvRows = [["label first","details of label 1"],["label sec","details of label 2"],["label 3","details of label 3"],["label 4","details of label 4 and 3"],["label 5","details of label 5"],["label 6","details of label 6"],["label 7","details of label 7"],["label 8","details of label 8"],["label 9","details of label 9"]];
var csvString = csvRows.join("%0A");
var a = document.createElement('a');
a.href = 'data:attachment/csv,' + csvString;
a.target = '_blank';
a.download = 'myFile.csv';
document.body.appendChild(a);
a.click();
}
</script>
<body>
<form action="" method="post">
<input type="button" value="Create" onclick="createCSV()">
</form>
</body>
</html>
Post a Comment for "How To Write Csv File Using Javascript?"