Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How Java uses POI to export Excel with large amounts of data

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you "how Java uses POI to export large amounts of data Excel". The content is simple and easy to understand, and the organization is clear. I hope it can help you solve your doubts. Let Xiaobian lead you to study and learn this article "how Java uses POI to export large amounts of data Excel".

profile

SXSSFWorkbook requires poi-ooxml package 3.8 and above to start supporting, I am using version 3.9, essentially an XSSFWorkbook class (Excel 2007), it uses the hard disk space to greatly reduce the heap memory occupation, in the system temporary folder directory to create a temporary file, and then all the data larger than the agreed number of rows are stored in the temporary file, rather than all in memory, memory only stores the latest agreed number of data, so as to achieve hard disk space in exchange for memory space, to avoid memory overflow

use

There is no difference from the normal Excel export method, just replace the instantiated class with SXSSFWorkbook

SXSSFWorkbook workbook = null; OutputStream outputStream = null; try { outputStream = response.getOutputStream(); //Create workbook workbook = new SXSSFWorkbook(); //Turn on compression to prevent excessive disk usage workbook. setCompressed TempFiles (true); //Create a worksheet Sheet = workbook.createSheet("Table Name"); //Create a Row titleRow = sheet.createRow(0);//Create a cell Cell = titleRow.createCell(0); //Assign cell.setCellValue("Content"); //Write workbook to output stream workbook.write(outputStream); } catch (Exception e) { e.printStackTrace(); }finally { if (workbook != null) { //delete temporary files generated after use to prevent disk from filling workbook.dispose(); } if (outputStream != null) { outputStream.close(); } }

The above is "Java how to use POI export large amounts of data Excel" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report