Code Monkey home page Code Monkey logo

dataparser's Introduction

dataParser

通用表格数据解析工具,目前支持xls、xlsx、csv、html、xml、txt形式的数据源,也支持InputStream解析,并且支持在较低内存占用下完成超大xlsx文件的解析。

支持jdk1.5及以上版本,jdk1.5需额外导入javax包,否则解析xlsx会报错。

##代码目录

  1. lib:依赖的jar
  • files:示例文件
  • samples:示例代码
  • captures:截图
  • data-parser.jar 最新的,项目中直接用这个jar(当然还得引用依赖的jar)

##更新日志

  1. 20160925 新增支持txt数据解析(含示例代码及文件)

##示例 ###待解析excel内容

A B C D E
1 序号 姓名 性别 年龄 民族
2 1 张三 20 汉族
3 2 李四 18 汉族
4 3 王二 30 满族

###java代码 //所有资源的解析都统一按以下几步走哦

//待解析资源,支持xls、xlsx、csv、html、xml、txt、inputStream
File file = new File("test.xls");

//自定义解析规则,这里使用列对应字母,数据Block从第1行开始(行从0开始计)
IParserRule rule = new ParserRuleLetter(1,"A","E");

//通过工厂获取解析器接口
IParser parser = ParserFactory.getInstance().getParser(file,rule);

//循环读取所有Block
Block block = null;
while(null!=(block = parser.nextBlock())){
  //显示Item内容
  System.out.print(block.getItemContent("A"));
  System.out.print("\t");
  System.out.print(block.getItemContent("B"));
  System.out.print("\t");
  System.out.print(block.getItemContent("C"));
  System.out.print("\t");
  System.out.print(block.getItemContent("D"));
  System.out.print("\t");
  System.out.println(block.getItemContent("E"));
  System.out.println("_____________________________________");
}

###输出结果

1 张三  男 20  汉族
_____________________________________
2 李四  女 18  汉族
_____________________________________
3 王二  男 30  满族
_____________________________________

##定义 ###1. Block块 每一条独立的信息记录定义为Block,一个表格中一般会有N个Block,下图中框起来的视为一个Block。Block目前支持三种类型:1、表头Block(head),2、数据Block(body),3、fragment中的数据Block(body_in_fragment)。如下图中,从序号为1的记录开始的3个Block,即为数据Block;从表格第一行直到遇到数据行之间的部分,统一划入一个表头Block;fragment中的数据Block见下方另行说明。

单行Block示例:

单行Block示例

多行Block示例:

多行Block示例

###2. Item格子 每一个独立的单元格定义为Item,下图中框起来的都视为Item,一个Block中通常会有N个Item。

Item示例

###3. Fragment分片 一个Block中可能会存在一块或多块相对独立的区域,这个区域中有多个小的Block,这些小Block用专门的类型以便与大Block区分(即body_in_fragment),这个区域定义为Fragment,下图中框起来的都是Fragment。

Fragment示例

dataparser's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.