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