"Build wheels" to create a simple universal Excel reading and writing tool

Source: Internet
Author: User

Do you work or do you usually encounter excel that reads and writes some simple formats?

shit! ~ Very egg hurts, because before bragging, has made a This thing, also is quite practical, and everybody share under.

Tired of having a simple type of Excel read and write every time? Not afraid of ~ come, like the flow of operation? Come on, like to use lambda (although the comparison of Java Egg Pain ~), to ~ See this ~

Haha, if you do not use java8~~ no problem, then silently use the old way anonymous class to achieve these functions, but this does not hinder your use haha ~ ~ ~

Updated many times ~ I hope you can also brainstorm ~

GitHub Address: https://github.com/MatrixSeven/ExcelReads

Welcome everyone fork, welcome to All Star, more welcome you more suggestions or suggestions, to provide better ideas ~ ~

Excelreads (Simple Excel general reader) what is Excelreads?
    • This is a generic simple Excel reader
    • Support for custom JavaBean entity reads and HashMap automatic reads
    • Support for custom extensions
    • Supports custom sheet range, data start line number
    • Support database Query Direct export Excel (Map/object)
    • Supports regular filtering data formats
    • JavaBean entities support the use of annotations to add regular rule validation, HashMap support for array rule validation
    • Rely on POI, build with Maven
Update 2017/01/05 for a new record
    • Fixed an export (Object) recursive cross-stack problem for library queries
    • Add the new XXX. class definition type export, easier operation
    • Export annotation Support (use Seven.savewapper.anno.ExcelAnno type annotations yourself)
Update 2017/01/04
    • Fixed export (MAP) NULL pointer & subscript cross-border problem for database query
    • Fixed a blank line problem after filter data
    • The action that is thrown into the result parameter is as map/object as the operation.
Update 2017/01/01
    • Add Resexprotdbmap&resexprotdbobj to support database export
    • Support for database query-based export (MAP), directly into the result object can be
    • Support for database query-based export (object) directly into the result object
Update 2016/11/30
    • Added a simple type to write to, generate XLS/XLSX
    • Direct JavaBean type writing, annotation naming
    • Supports map Key-value type write
    • Write-on support and read the same filter processing sorting and other wording
Update 2016/11/29
    • Add Createmap by Key
    • Remove useless generics
    • Add xlsx Support
Update 2016/11/8
    • Support for data filtering and processing is conversion, based on event mode
    • Update create instance for build mode
    • Increased data filtering, data conversion, and data sorting callback interfaces
    • The chain-set method is used to
Other
    • Custom reads support a simple canonical data format, which is a typical header format
    • Can inherit Wappermap and wapperobj for expansion
    • Get directly using Excelfactory.getbeans and wapperobj add generics yourself
    • Note value corresponds to the column header, required corresponding regular, can write their own regular expression or directly use Reghelper
    • Entity bean data is slower than HashMap, 7w data is 800ms slow, join the regular slow speed (the test added a regular)
Instructions for how to use
    1. This program can only read the simple format of the XLS file, the file layout is as follows (standard row and column structure):
Title 1 Title 2 Title 3
Foo Foo Foo
Bar Bar Bar
Baz Baz Baz
Database export custom Bean type notation (xxx.class type)
1 Excelfactory.saveexcel (2        unpooled_data_source.getconnection (). 3                 Preparestatement ("select * from  users_info limit"). ExecuteQuery (),4         "\u5317\u4eac_ _excel.xlsx ",5as          .  Class)6     new string[]{"UpdateTime"})7     . Filter ((as O)->o.geta (). Length () > 3)8     . Save ();

Database export custom Bean type notation (self-fulfilling wrapper)
Excelfactory.saveexcel (        unpooled_data_source.getconnection ().                Preparestatement ("select * from  users_info limit"). ExecuteQuery (),        "\u5317\u4eac__ Excel.xlsx ",             {                new as ();                A.seta (res.getstring ("name"));                 return A;            })     New string[]{"UpdateTime"})    ->o.geta (). Length () > 3)    . Save ();

Database export directly to Excel example
Excelfactory.saveexcel (        unpooled_data_source.getconnection ().                Preparestatement ("select * from  users_info limit 10000").                " Export excel.xlsx ")        // filter field   new string[]{" UpdateTime "})         // filter data conditions   . Filter ((hashmap<string, string> o),            O.get ("Address"). Equals ("\u5317\u4eac"))   . Save ();

Export custom types to Excel examples
list<a> AA =NewArraylist<>(); Aa.add (NewA ("A", "B")); Aa.add (NewA ("AA", "BB")); Excelfactory.saveexcel (AA, System.getproperty ("User.dir"). Concat ("\\Save.xlsx")))        ///can handle every row of data here. Process ((a A), A.seta ("xxxxxxx"))        //Filter Columns. Filtercol (()Newstring[]{"B"})        //discard when processing data according to a field. Filter ((a A), A.geta (). Length () > 1)        //Sort. Sort ((A o1,a O2), O1.getage () >o2.getage ()? 1:o1.getage () ==o2.getage ()? 0:-1)        . Save ();

Read Excel to map example
1List<map<string,string>> Data=excelfactory.getbeans (System.getproperty ("User.dir"). Concat ("\ \ Test. xls "),2                 NewReswrappermap () {3@Override//Configure Excel Properties4                     protected voidloadconfig (config config) {5Config.setcontent_row_start (3);6Config.settitle_row (2);7                     }8}).//You can handle every row of data here.9Process ((hashmap<string, string> o), System.out.println (o + "\ n"))Ten                 //This is the time to filter a column . One). Filtercol (()Newstring[]{} A                 //This can be based on the contents of a column of a row to choose the row of data -). Filter ((hashmap<string, string> o), O.get ("creator")! =NULL&& O.get ("creator"). Length () > 5 -                 //Sort the). Sort (O1, O2), O1.hashcode () >o2.hashcode ()? 1:hashcode () ==o2.hashcode ()? 0:-1). Create (); -  - //use. Createmap (KEY_V) generates map<key,map> type data

Example of reading Excel to a custom type
1Map<string,seven> map=NewReswrapperobj (Seven) {2 @Override3                     protected voidloadconfig (config config) {4Config.setcontent_row_start (3);5Config.settitle_row (2);6                     }7                 }).8Process ((hashmap<string, string> O) {}9). Filtercol (()Newstring[]{}Ten). Filter ((hashmap<string, string> o), O.get ("creator")! = One         NULL&&o.get ("creator"). Length () > 4). <map>createmap ("creator"));

    • Email ([email protected])
    • qq:985390927
    • Weibo: @Alden_ Emotional control
    • Blog:http://sweets.cf

"Build wheels" to create a simple universal Excel reading and writing tool

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.