使用javascript将数据插入CSV文件 [英] Insert data into CSV file using javascript

查看:94
本文介绍了使用javascript将数据插入CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MY C ++ APPLICATION正在读取数据表格device.e.g温度传感器。传感器在1秒后传输更新。但是我想在使用java脚本将温度随当前时间戳改变为CSV文件时插入传感器更新数据。这是我第一次需要创建一个新文件,之后只更新以前的文件。

MY C++ APPLICATION is reading data form device.e.g Temperature sensor. Sensor is transmitting update after 1 seconds. But I want to insert the sensor update data only when temperature changed with current timestump into CSV file using java script.For the first time i need to create a new file and afterwords just update the previous file.

Required CSV file
Time                     Temp(C)
12:30:12:325              57
12:30:15:351              56
12:30:17:453              57





我的尝试:



HTML + JS。

----------

< html>

< script type =text / javascript>

函数createCSV(){

csvRows = [[标签第一,标签1的详细信息],[标签sec,标签2的详细信息,[标签3,标签3的详细信息],[标签4,标签4和3的详细信息],[标签5,详细信息标签5],[标签6,标签6的详细信息],[标签7,标签7的详细信息],[标签8,标签8的详细信息],[标签9,标签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 =buttonvalue =Create>

< / form>

< / body>

< / html>



What I have tried:

HTML+JS.
----------
<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" >
</form>
</body>
</html>

推荐答案

Javascript不是为编写文件而设计的。这是一个安全功能,以确保浏览器不会操纵任何PC。



但是当你有一个C ++应用程序时,你已经拥有完整的本机能力。以下是用于编码文件访问的一些教程。在你的应用程序中,你必须有一些变量或更好的对象与最后的值,如果更改你附加数据。
Javascript isnt crafted for writing files. It is a security feature to ensure that browsers dont manipulate any PC.

But when you have a C++ App you already have the full native power. Here is some tutorial for coding file access. In your app you must have some variables or better objects with the last values and if changed you append the data.


这篇关于使用javascript将数据插入CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆