Is it possible to save the data from local storage to a csv file?
First i want to fill in a html form, after that Some pictures are shown with rating buttons. My idea is to store all the input in the local storage and then save all to a csv file (this should be saved on a server) Is there any way to save all the data at the end to a csv file?
Is it possible to save the data from local storage to a csv file?
First i want to fill in a html form, after that Some pictures are shown with rating buttons. My idea is to store all the input in the local storage and then save all to a csv file (this should be saved on a server) Is there any way to save all the data at the end to a csv file?
Share Improve this question asked May 7, 2013 at 21:26 user2355759user2355759 431 silver badge3 bronze badges 2- "this should be saved on a server" - Which server-side language(s) are you using? You can certainly submit the data from the browser to the server (possibly with Ajax), but how you'd make the server save a CSV would depend on the server technology/language. – nnnnnn Commented May 7, 2013 at 21:29
- I thougt of using php to save it on the server – user2355759 Commented May 7, 2013 at 21:31
1 Answer
Reset to default 5Using Blob (https://developer.mozilla/en/docs/DOM/Blob) this seems achievable. First generate the file from the local store then blast it off to the server however you like. This should get you going in the right direction:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSV Export</title>
<script>
function exportData() {
var item = localStorage.csv=",what you want in the CSV,";
var ary = localStorage.getItem( "csv" ); //csv as a string
var blob = new Blob([ary], {type: "text/csv"});
var url = URL.createObjectURL(blob);
var a = document.querySelector("#results"); // id of the <a> element to render the download link
a.href = url;
a.download = "file.csv";
}
</script>
</head>
<body>
<button onclick="exportData()">Download CSV</button><br>
<a id="results">CSV from local store</a>
</body>
</html>
Getting the file onto the server is another matter but you should be able to tweak this and use PHP, .NET or whatever else.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745091892a4610741.html
评论列表(0条)