2013年8月13日星期二

oh my god, write data to Excel 200000

just 9 seconds
 

rookie when, at some. Net project, users need to export from the business system Report, while the amount of data is usually in the upper ten thousand or more, the approach is to initially server-side generated using NPOI to Excel, Data line by line to a Cell a Cell written to each Cell in Excel, if the user Report format requires a little higher, but also a Cell a Cell set the cell's Style, then the Report for users to download. Results on ten thousand users to export data requires several minutes. Export this Report, is a crazy person to be. . . . .

 

time, the boss did not give pressure, just say, can get, I'll get it working from the outside to find experts to solve, 16:00 give me an answer, there is pressure to have power, and finally in an article posted in Technology found that using NPOI Excel has written more convenient and faster way, data can be organized into two-dimensional array to Excel in a write-once the Range, Style can also be set directly through the Range . After optimization, exporting only tens of thousands of pieces of data, the boss smiled. Posted the most classic lines of code

 

Range range = xst.get_Range (excel.Cells [0, 0], excel.Cells [9999,9999]);

 

range.Value2 = datas; / / datas as a two-dimensional data data <​​p>  

again this year in a Java project, the old rookie became the lead brother, a younger brother with a conventional ideas derived Report, even tens of thousands of pieces of data need ten minutes, but occasionally reported memory overflow, it is when people crash. Checked the API, Java in the apache POI did not Range write Excel interface, but it provides a one-time write Excel via XML way, Demo for a moment, write 200,000 data to Excel, just 9 seconds . This time I laughed. . . .

 

refer to the following URL:

 

http://libjakarta- poi-java.sourcearchive.com/documentation/3.6plus-pdfsg/BigGridDemo_8java-source.html

 

 

QQ: 251171985

 

E-Mail: jthuahua@126.com

没有评论:

发表评论