Java read CSV and Excel

Source: Internet
Author: User

1, CSV and Excel read and write comparison

Data import and export functions are often encountered in development, and CSV and Excel are the most common data formats, and this article compares the efficiency of reading and writing the same data in CSV and Excel:

The same format compares the same number of rows:

    • CSV file is slightly larger than Excel file
    • CSV read/write faster than Excel

The following is a comparison of reading and writing the same format data:

CSV file reading Tool class

Excel file Reading Tool class

Tool class can be seen: CSV read and write is implemented in the unit of behavior, Excel read InputStream is directly loaded into memory.

If you use the above Excel tool class to read and write general requirements can be met, if you encounter a large amount of data read and write, the use of inputstream loaded into memory may have an oom problem.

2, Excel large amount of data write

The Excel tool class handles a large number of write problems (Sxssfworkbook shards write to Excel, the 100w test data in the example above is written in this way):

    /*** Create a workbook *@paramFileType *@return     * @throwsException*/    Private StaticWorkbook Createworkbook (String fileType)throwsIOException {Workbook wb; if(Excel2003l.equals (FileType)) {//2003-WB =NewHssfworkbook (); } Else if(Excel2007u.equals (FileType)) {//2007+ Memory Retention dataWB =NewSxssfworkbook (10000); } Else {            Throw NewIOException ("Parsed file format is incorrect! "); }        returnWB; }
3, Excel large data read

Large amount of data read directly using workbook loading will occur Oom exception, a good way is to read in batches, reference: Excel bulk Data read

Java read CSV and Excel

Related Article

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.