admin管理员组文章数量:1431726
I am using Google Map API and CSV file to plot the data on the map. Now I want to update the CSV file using JavaScript, so that the plotted points can be shown as moving objects in the map. I have used an active-X object. It updates the CSV file in IE only. Here is the JavaScript code:
var test = [
"2015-03-03 18:12:12.297,1,19.1618,73.002,0.0",
"2015-03-03 18:12:12.297,2,19.158141,73.000202,0.0",
"2015-03-03 18:12:12.297,10,19.158141,73.000201,0.0"
];
function file() {
for(var i=0; i < test.length; i++) {
setTimeout(function() {
time(i);
}, 10000);
}
}
function time(i) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fileLoc = "D:\\test.csv";
var file = fso.OpenTextFile(fileLoc, 2, true, 0);
file.writeline(test[i]);
file.Close();
alert('File created successfully at location: ' + fileLoc);
}
I need to update the data every 10 sec. I am approaching for the way to delete the existing latlong in CSV and put new latlong so the the object can be seen as a moving one.
I am using Google Map API and CSV file to plot the data on the map. Now I want to update the CSV file using JavaScript, so that the plotted points can be shown as moving objects in the map. I have used an active-X object. It updates the CSV file in IE only. Here is the JavaScript code:
var test = [
"2015-03-03 18:12:12.297,1,19.1618,73.002,0.0",
"2015-03-03 18:12:12.297,2,19.158141,73.000202,0.0",
"2015-03-03 18:12:12.297,10,19.158141,73.000201,0.0"
];
function file() {
for(var i=0; i < test.length; i++) {
setTimeout(function() {
time(i);
}, 10000);
}
}
function time(i) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fileLoc = "D:\\test.csv";
var file = fso.OpenTextFile(fileLoc, 2, true, 0);
file.writeline(test[i]);
file.Close();
alert('File created successfully at location: ' + fileLoc);
}
I need to update the data every 10 sec. I am approaching for the way to delete the existing latlong in CSV and put new latlong so the the object can be seen as a moving one.
Share Improve this question edited Jan 19, 2017 at 14:12 ssc-hrep3 16.1k8 gold badges51 silver badges96 bronze badges asked May 4, 2016 at 4:20 sachinsachin 411 gold badge1 silver badge3 bronze badges 3- Maintaining data record in plain text can be tricky. Is it possible to maintain data structure in program / database level, and replace the plain text if the I/O is limited? – ydoow Commented May 4, 2016 at 5:06
- I would keep an array of cells (array of array) in the memory of the JavaScript app and continuously print this array with a formatting function to the CSV file. It is much easier to overwrite the file with your current in-memory data, than editing CSV files. By the way, ActiveX won't work in browsers other than IE. – ssc-hrep3 Commented Jan 19, 2017 at 14:17
- Possible duplicate of How can I create a file for storage on the client side with JavaScript? – Tibrogargan Commented Apr 30, 2017 at 22:38
1 Answer
Reset to default 2I believe storing a file on client side is not considered secure as per the standards and therefore not allowed [1]
However per your use case :
CSV file to plot the data on the map....I need to update the data every 10 sec...to delete the existing latlong in CSV and put new latlong
You have this js var in your code
var test = [
"2015-03-03 18:12:12.297,1,19.1618,73.002,0.0",
"2015-03-03 18:12:12.297,2,19.158141,73.000202,0.0",
"2015-03-03 18:12:12.297,10,19.158141,73.000201,0.0"];
So instead you could try JS local storage [2], maybe something like this
//set in local storage
localStorage.setItem('test','"2015-03-03 18:12:12.297,1,19.1618,73.002,0.0","2015-03-03 18:12:12.297,2,19.158141,73.000202,0.0","2015-03-03 18:12:12.297,10,19.158141,73.000201,0.0"');
//retrieve from local storage
var test2= localStorage.getItem('test');
console.log(test2);
[1] How can I create a file for storage on the client side with JavaScript?
[2] https://developer.mozilla/en-US/docs/Web/API/Window/localStorage
本文标签: How to update csv file using javascriptStack Overflow
版权声明:本文标题:How to update csv file using javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745494367a2660743.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论