如何使用javascript从*.CSV文件中读取数据? - How to read data From *.CSV file using javascript?

10/14 12:44
阅读数 0

问题:

My csv data looks like this:我的 csv 数据如下所示:

heading1,heading2,heading3,heading4,heading5,value1_1,value2_1,value3_1,value4_1,value5_1,value1_2,value2_2,value3_2,value4_2,value5_2....标题1,标题2,标题3,标题4,标题5,值1_1,值2_1,值3_1,值4_1,值5_1,值1_2,值2_2,值3_2,值4_2,值5_2....

How do you read this data and convert to an array like this using Javascript?:您如何使用 Javascript 读取这些数据并转换为这样的数组?:

[heading1:value1_1 , heading2:value2_1, heading3 : value3_1, heading4 : value4_1, heading5 : value5_1 ],[heading1:value1_2 , heading2:value2_2, heading3 : value3_2, heading4 : value4_2, heading5 : value5_2 ].... [heading1:value1_1,heading2:value2_1,heading3:value3_1,heading4:value4_1,heading5:value5_1],[heading1:value1_2,heading2:value2_2,heading3:value3_2,heading4:value4_2,heading5:value5_2]...

I've tried this code but no luck!:我试过这段代码,但没有运气!:

<script type="text/javascript">
    var allText =[];
    var allTextLines = [];
    var Lines = [];

    var txtFile = new XMLHttpRequest();
    txtFile.open("GET", "file://d:/data.txt", true);
    txtFile.onreadystatechange = function()
    {
        allText = txtFile.responseText;
        allTextLines = allText.split(/\r\n|\n/);
    };

    document.write(allTextLines);<br>
    document.write(allText);<br>
    document.write(txtFile);<br>
</script>

解决方案:

参考一: https://en.stackoom.com/question/VBDA
参考二: https://stackoom.com/question/VBDA
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部