All Projects → houbb → csv

houbb / csv

Licence: Apache-2.0 license
The csv read/write tool based on java annotation.(基于 java 注解的 CSV 文件读写框架工具。)

Programming Languages

java
68154 projects - #9 most used programming language
shell
77523 projects
Batchfile
5799 projects

Projects that are alternatives of or similar to csv

flextures
This plug-in can load and dump test data in databases, loading function is very flexible, dump function is very simple
Stars: ✭ 21 (-4.55%)
Mutual labels:  csv-export, csv-import
Windmill
A library to parse or write Excel and CSV files through a fluent API
Stars: ✭ 19 (-13.64%)
Mutual labels:  csv-reader, csv-export
smuggle
Manage exports and imports with ease, separating the logic from the models
Stars: ✭ 30 (+36.36%)
Mutual labels:  csv-export, csv-import
csvlixir
A CSV reading/writing application for Elixir.
Stars: ✭ 32 (+45.45%)
Mutual labels:  csv-export, csv-import
adversaria
Typeclass interfaces to access user-defined Scala annotations
Stars: ✭ 22 (+0%)
Mutual labels:  java-annotations
sketch-library-audit
Export Symbol and Shared Style data from any Sketch Library to CSV.
Stars: ✭ 17 (-22.73%)
Mutual labels:  csv-export
vertx-mybatis
vertx sqlclient template using mybatis NON-BLOCK & ASYNCHRONOUS
Stars: ✭ 23 (+4.55%)
Mutual labels:  csv-export
Adaptivetablelayout
Library that makes it possible to read, edit and write CSV files
Stars: ✭ 1,871 (+8404.55%)
Mutual labels:  csv-reader
csv2influx
A CLI tool for importing CSV files into Influxdb
Stars: ✭ 16 (-27.27%)
Mutual labels:  csv-import
VBA-CSV-interface
The most powerful and comprehensive CSV/TSV/DSV data management library for VBA, providing parsing/writing capabilities compliant with RFC-4180 specifications and a complete set of tools for manipulating records and fields.
Stars: ✭ 24 (+9.09%)
Mutual labels:  csv-reader
CsvTextFieldParser
A simple CSV parser based on Microsoft.VisualBasic.FileIO.TextFieldParser.
Stars: ✭ 40 (+81.82%)
Mutual labels:  csv-reader
java-read-write-csv-file
Read and Write CSV files in Java using Apache Commons CSV and OpenCSV
Stars: ✭ 57 (+159.09%)
Mutual labels:  csv-reader
Unity-File-Debug
Enhanced debug logging for Unity, with JSON/CSV export and HTML viewer.
Stars: ✭ 50 (+127.27%)
Mutual labels:  csv-export
gag
This project is a fork of Google Annotation Gallery
Stars: ✭ 42 (+90.91%)
Mutual labels:  java-annotations
DbExporterHelper
This small Library Helps you to export db , export to csv and import db also work with Room db
Stars: ✭ 26 (+18.18%)
Mutual labels:  csv-export
ExcelExport
Classes to generate Excel/CSV Report in ASP.NET Core
Stars: ✭ 39 (+77.27%)
Mutual labels:  csv-export
Cursively
A CSV reader for .NET. Fast, RFC 4180 compliant, and fault tolerant. UTF-8 only.
Stars: ✭ 34 (+54.55%)
Mutual labels:  csv-reader
lazycsv
A fast, lightweight and single-header c++ csv parser library
Stars: ✭ 53 (+140.91%)
Mutual labels:  csv-reader
graphql-cli-load
A graphql-cli data import plugin to call mutations with data from JSON/CSV files
Stars: ✭ 63 (+186.36%)
Mutual labels:  csv-import
cuba-component-data-import
CUBA component for easy data import
Stars: ✭ 19 (-13.64%)
Mutual labels:  csv-import

csv

CSV 是基于 java 注解的 csv 读写框架,让你更加优雅方便的操作 csv。

Maven Central Build Status Open Source Love

相关框架

Apache commons-csv

super-csv

简单看了下,这两个框架提供的特性都非常的基础。

创作原由

以前觉得 csv 文件的读写非常简单,就懒得封装。

最近一个月写了两次 csv 文件相关的东西,发现要处理的细节还是有的,还浪费比较多的时间。

比如:

  1. UTF-8 中文编码使用 excel 打开乱码,因为缺少 BOM 头。

  2. 不同类型字段转化为字符串,顺序的指定,head 头的指定,如果手写都会很繁琐。

  3. 读取的时候最后 , 后无元素,split 会缺失等。

为了解决上述问题,此框架应运而生。

特性

  • Fluent 流式写法

  • 基于 java 注解,支持自定义的转换和灵活配置

  • 内置 8 大基本类型以及 String 类型转换

  • 解决 Excel 直接打开,utf-8 乱码问题

  • 支持集合、数组、Map 的存取

  • 支持对象中内嵌其他对象

  • 支持特殊字符转义

v0.1.0 变更

  • 枚举值映射

支持快速简单的枚举值映射

快速开始

环境

jdk7+

maven 3.x

maven 引入

<dependency>
    <groupId>com.github.houbb</groupId>
    <artifactId>csv</artifactId>
    <version>0.0.9</version>
</dependency>

示例代码

写入

详情参考 CsvHelperWriterTest.java

final String path = "src\\test\\resources\\helper.csv";

CsvHelper.write(buildCommonList(), CsvWriters.filePath(path));
  • 文件生成
name,age,score,money,sex,level,id,status,coin
你好,10,60.0,200.0,true,4,1,Y,1

读取

详情参考 CsvHelperReaderTest.java

  • 读取文件
final String path = "src\\test\\resources\\common.csv";

List<User> userList = CsvHelper.read(path, User.class);
Assert.assertEquals("[User{name='你好', age=10, score=60.0, money=200.0, sex=true, level=4, id=1, status=Y, coin=1}]", userList.toString());
  • 读取字符串列表

也支持直接读取字符串列表。

List<String> lines = Arrays.asList("name,age,score,money,sex,level,id,status,coin",
                "你好,10,60.0,200.0,true,4,1,Y,1");

List<User> userList = CsvHelper.read(lines, User.class);
Assert.assertEquals("[User{name='你好', age=10, score=60.0, money=200.0, sex=true, level=4, id=1, status=Y, coin=1}]", userList.toString());

对象信息

其中使用的属性如下:

  • User.java

演示基本类型的转换

public class User {

    private String name;

    private int age;

    private float score;

    private double money;

    private boolean sex;

    private short level;

    private long id;

    private char status;

    private byte coin;

    //Getter & Setter & toString()
}
  • 对象列表构建
    /**
     * 构建通用测试列表
     * @return 列表
     */
    private List<User> buildCommonList() {
        User user = new User();
        short s = 4;
        byte b = 1;
        user.age(10)
        .name("你好")
        .id(1L)
        .score(60)
        .coin(b)
        .level(s)
        .money(200)
        .sex(true)
        .status('Y');
        return Arrays.asList(user);
    }

拓展阅读

01-CSV 引导类方法说明

02-CSV 字段注解的使用

03-CSV 集合相关支持

04-CSV 内嵌对象使用

05-CSV 内嵌对象使用

后期 road-map

  • 引入 @Order 注解或者新增 order() 注解属性

避免 java 反射存在的字段顺序和声明顺序不一致问题

  • 使用 converter 项目统一优化

读写转换等操作统一复用。

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].