使用Javascript上传和解析CSV文件 [英] uploading and parsing a CSV file using Javascript

查看:435
本文介绍了使用Javascript上传和解析CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前的环境是使用Javascript,HTML,File API来上传文件。目前,我一直在研究如何阅读File API上传的CSV文件,例如:

My current environment is using Javascript, HTML, File API to upload files. At the moment, I have been research on how to read a File API-uploaded CSV file such as:

Id,Event type,Start,Stop,Timezone,Precision,Entity,Momentum,Financial positive sentiment,Financial negative sentiment,General positive sentiment,General negative sentiment,Fragment,Document category,Document title,Document url,Document published,Source name,Source media type,Source topic,Source country,Attributes
GQcBzYAEAJL,Buybacks,2/7/2013 19:00,2/8/2013 18:59,America/New_York,day,,0.25,0.22,0.44,0.22,0,"Share buy back DMGT's strong operational cash flow and disciplined management of our portfolio of businesses has resulted in a net debt to EBITDA ratio of 1.6, falling to well below our stated internal limit of 2.4 times.",Business_Finance,Daily Mail & General : Preliminary Results 2011/12,http://www.investegate.co.uk/article.aspx?id=20121122070000PDC35,11/22/2012 3:03,Investegate.co.uk,Niche,None,United Kingdom,company:Daily Mail & General Trust|fragment_count:1|inherited_locations:[DMGT]
GQf0LxASVpP,Company Layoffs,1/31/2013 19:00,2/1/2013 18:59,America/New_York,day,,0.03,0,0.31,0,0,"As a result, Quadel will need to reduce its workforce by 64 employees beginning on or about Feb. 1, concluding no later than 14 days afterward.",Labor,Florida Quadel Consulting to lay off 64 in Miami,http://feeds.bizjournals.com/~r/bizj_southflorida/~3/bdu_17A5w6M/florida-quadel-consulting-to-lay-off.html,12/3/2012 14:50,Bizjournals.com (8237),Niche,None,United States of America,authors:[Shaun Bevan]|company:Quadel Consulting Corp|fragment_count:1|status:planned
GQYBsgACGKI,Company Layoffs,1/30/2013 19:00,1/31/2013 18:59,America/New_York,day,,0.46,0,0.26,0,0,"The parent group unveiled a ""reduction of 4.500 jobs to safeguard around 15.500 posts across the airline"" -- meaning Iberia was on course to shed almost one quarter of its staff.",Business_Finance,"Iberia survival plan: slash quarter of jobs, cut 15% network and downsize fleet",http://en.mercopress.com/2012/11/10/iberia-survival-plan-slash-quarter-of-jobs-cut-15-network-and-downsize-fleet?utm_source=feed&utm_medium=rss&utm_content=main&utm_campaign=rss,11/9/2012 23:40,MercoPress,Mainstream,General,Uruguay,company:IBERIA LINEAS AEREAS DE ESPANA SA|employees_number:one|fragment_count:1|status:announced

可下载的CSV档案这里

Downloadable CSV file here

例如,将所有列标题和行数据等输出到HTML上显示的表中

For instance, output all the column headings, and row data etc to a table displayed on the HTML

大多数在线研究似乎集中在传入csv数据类似于JSON数据。但我似乎不能找到一个解析CSV文件。

Most of the research online seems to focus on incoming csv data similar to JSON data. But I cannot quite seem to find one that parses a CSV file. Any help or direction will be much appreciated.

推荐答案

通常,CSV文件包含用分隔符分隔的单元格,例如; :在您的示例中,分隔符为。所以你需要做的是:

Usually CSV files contains cells divided by a separator, like ;: in your example the separator is ,. So what you need to do is:

1)将你的CSV文件读入一个 String name 输入;

1) Read your CSV file into a String, for example you can name it input;

2)创建一个字符串数组 String [] result = input.split(\\,); ;

2) Create a String Array like this String[] result = input.split("\\,");;

3)迭代您的 code>。

3) Iterate your result as you wish.

这篇关于使用Javascript上传和解析CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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