Export Excel features (solve large data volume problems) __c language

Source: Internet
Author: User

Now we do the system, export Excel features have a problem, if the amount of data (such as more than tens of thousands of records), if the traditional way to export Excel speed is very slow, and even eventually lead to memory benefits, the final crash; (please all the best to confirm the problem of the system in charge)

For example: Sanming Mobile Company's integration system, due to the needs of the customer, if you want to export 20多万条 records, the system speed is very slow, resulting in the memory of the crash; originally thought is frequently put the data in the collection of reasons, but I also have pagination feel is not the main reason, after with Huang discussion and test, The discovery is mainly because of the frequent insertion of data into Excel, a large amount of data will occupy the system a lot of memory, so we'd better not use Java-provided operations Excel API (Hssfworkbook workbook = new Hssfworkbook (); )

here It is recommended to insert the record directly into the text file (fast, less memory), and then cut off the representative of a column, then the resulting file, directly with Excel to open the. as follows:
String path= "C:/test.xls";/Where data is stored
BufferedWriter buff = new BufferedWriter (new FileWriter (path));//Generate file
Insert Title
Buff.write ("department name \ t user \ t Phone");//Represents 3 columns
Buff.write ("\ r \ n");/linefeed
Insert 50,000 records
for (int i = 0; i < 50000; i++) {
Buff
. Write ("SMS Business Hall \ t Xiao Wu \t123456");
Buff.write ("\ r \ n");
}
Buff.close (); Turn off file operations

Note: Due to open excel when a sheet only show about 65,000 records, so record more than 5, 60,000, the recommended generation of multiple files, a file of 50,000 lines or so good

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.