jquery读取csv文件并用json格式输出

直接贴上代码:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
     <title>Untitled Page</title>
</head>
<script language="javascript" src="jquery-1.8.3.min.js"></script>
<script language="javascript" src="csv.js"></script>
<script language="javascript" type="text/javascript">
function importXLS(){
     if (!(window.File || window.FileReader || window.FileList || window.Blob)) {
         alert(‘请使用Chrome浏览器!‘);
     }
     var files = $(‘input[name="fileTrans"]‘).prop(‘files‘);//获取到文件列表

     if(files.length == 0){
       alert(‘请选择文件‘);
       return;
     }else{
       var reader = new FileReader();//新建一个FileReader
       reader.readAsText(files[0], "gbk");//读取文件
       reader.onload = function(evt){ //读取完文件之后会回来这里
         var fileString = evt.target.result;
          var a = new CSV(fileString, {
            header: [‘username‘, ‘pay_money‘, ‘pay_type‘]
          }).parse();

          console.log(a);
       }
     }
     }
</script>
</head>
<body>
<input type="file" name="fileTrans" id="f" />
<input type="button" id="b" value="import" onclick="if(f.value==‘‘)alert(‘请选择csv文件‘);else importXLS()" />
</body>
</html>

  这里用到了两个类:

FileReader();
CSV();基本上能够兼容谷歌和360浏览器。

花了半天时间研究,如果你喜欢就加我好友吧。
时间: 2024-07-28 14:22:11

jquery读取csv文件并用json格式输出的相关文章

js读取csv文件为json显示

摘要: 前面分享了用js将json数据下载为csv文件,方便后期管理.但是对于测试人员更希望能够以页面的形式展现任务,所以就做了一个将csv文件展现在页面上的例子. 代码: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <title>csv</titl

按格式读取csv文件内容

string path = @"C:\Users\keen_\Downloads\upload\upload\Upload\20140701141934_export.csv"; ImportDataTable(path); //2014-07-01 //get csv file to datatable private static DataTable ImportDataTable(string filepath) { DataTable mydt = new DataTable(

Spring Batch示例: 读取CSV文件并写入MySQL数据库

Spring Batch示例: 读取CSV文件并写入MySQL数据库 GitHub版本: https://github.com/kimmking/SpringBatchReferenceCN/blob/master/01_introduction/Spring_Batch_MySQL.md 原文链接: Reading and writing CVS files with Spring Batch and MySQL 原文作者: Steven Haines - 技术架构师 下载本教程的源代码: S

Spring Batch使用示例: 读取CSV文件并写入MySQL数据库

GitHub版本: https://github.com/kimmking/SpringBatchReferenceCN/blob/master/01_introduction/Spring_Batch_MySQL.md ------------ 编写批处理程序来处理GB级别数据量无疑是种海啸般难以面对的任务,但我们可以用Spring Batch将其拆解为小块小块的(chunk). Spring Batch 是Spring框架的一个模块,专门设计来对各种类型的文件进行批量处理. 本文先讲解一个简

Cocos2d-x Lua 读取Csv文件,更方便的使用数据

我的书上或者是我曾经出售的源码里,都有Csv文件的影子. 也许是先入为主吧,我工作那会用的最久的配置文件就是Csv,所以我在很多游戏里都会情不自禁地优先选择它. Csv文件,格式很简单,就是一行一条数据,字段之间用逗号分隔,策划也可以方便地使用Excel进行编辑. Csv格式的文件,解析起来也很简单,所以自己动手写写很快~(小若:我就喜欢拿来主义,你怎么着) 最近在用Lua写游戏,对于技能.怪物等配置,我还是选择用Csv~ 不得不说,Lua等脚本语言,在某些方面是C++没法比的,这次我就用Csv

C++ 把数组数据存入 CSV 文件,以及读取 CSV 文件的数据

1. CSV-百度百科 2. 代码 #pragma once //Microsoft Visual Studio 2015 Enterprise #include<iostream> #include<fstream> #include<string> #include<vector> #include<cstdio> #include<cstdlib> using namespace std; template<typenam

sparkR读取csv文件

sparkR读取csv文件 The general method for creating SparkDataFrames from data sources is read.df. This method takes in the path for the file to load and the type of data source, and the currently active SparkSession will be used automatically. SparkR suppo

读取csv文件,写入oracle数据库

/* * @(#)DataParse.java 2014年4月28日 */ package com.yihaodian.sa.doData; import java.io.BufferedReader;import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;import java.sql.Connection;import java.

用程序读取CSV文件的方法

CSV全称 Comma Separated values,是一种用来存储数据的纯文本文件格式,通常用于电子表格或数据库软件.用Excel或者Numbers都可以导出CSV格式的数据. CSV文件的规则 0 开头是不留空,以行为单位.1 可含或不含列名,含列名则居文件第一行. 2 一行数据不垮行,无空行. 3 以半角符号,作分隔符,列为空也要表达其存在. 4 列内容如存在,,则用""包含起来. 5 列内容如存在""则用""""包