Java report tool FineReport exports EXCEL in four ways

Source: Internet
Author: User

Java report tool FineReport exports EXCEL in four ways

In actual applications, you often need to export data to excel. The export methods include page export, sheet export, and big data export, in addition to the original export method. For excel2003, the maximum number of rows and columns of each sheet are limited. When exporting large data volumes, multiple sheets are created by default, but excel2007 does not. These export methods are implemented using different interfaces in the JAVA program:

1. Export as is

To export an excel file without Preview

The program interface code is as follows:

OutputStream = new FileOutputStream (new File ("E: \ ExcelExport.xls"); ExcelExporter excel = new ExcelExporter (); // export outputStream 2007 = new FileOutputStream (new File ("E :\\ ExcelExport.xlsx"); excel Excel2007Exporter excel = new Excel2007Exporter (); excel. export (outputStream, rworkbook );

:

 

2. Export by PAGE

Pagination export: if the report template is paginated, it will be exported in the form of pagination results, and duplicate titles will also be repeated.

The program interface code is as follows:

OutputStream = new FileOutputStream (new File ("E: \ PageExcelExport.xls"); PageExcelExporter page = new PageExcelExporter (ReportUtils. export (rworkbook); // export version 2007 outputStream = new FileOutputStream (new File ("E: \ Users"); excel PageExcel2007Exporter page = new PageExcel2007Exporter (ReportUtils. getPaperSettingListFromWorkBook (rworkbook); page. export (outputStream, rworkbook );

:


 

3. Export data by page in sheet

When a Sheet is exported by PAGE, each page of the table result is saved as a Sheet in an Excel file.

The Code is as follows:

OutputStream = new FileOutputStream (new File ("E: \ PageSheetExcelExport.xls"); PageToSheetExcelExporter sheet = new PageToSheetExcelExporter (ReportUtils. export (rworkbook); // export version 2007 outputStream = new FileOutputStream (new File ("E: \ Users"); excel PageToSheetExcel2007Exporter sheet = new PageToSheetExcel2007Exporter (ReportUtils. getPaperSettingListFromWorkBook (rworkbook); sheet. export (outputStream, rworkbook );

:


4. export large data volumes

This is common, for example, behavior of an excel file at 50000

The Code is as follows:

OutputStream = new FileOutputStream (new File ("E: \ LargeExcelExport.zip"); LargeDataPageExcelExporter large = new LargeDataPageExcelExporter (ReportUtils. export (rworkbook), true); // export outputStream 2007 = new FileOutputStream (new File ("E: \ LargeExcelExport.xlsx"); excel export large = new Preview (ReportUtils. getPaperSettingListFromWorkBook (rworkbook), true); large. export (outputStream, rworkbook );

 

When exporting a report with a large amount of data, the following two situations may occur:

1. The data is successfully exported and displayed in multiple sheets;

2. Failed to export. The exported Excel content is invalid. There are two main reasons for the above situation:

4.1 The row engine is not enabled for exporting large data reports

If the row engine is not enabled, the export is successful if the server can afford it. If the server cannot afford it, the export fails, let's take a look at the results:

4.1.1 within the scope of the server

The acceptable range is: The data volume is large, exceeding the maximum number of rows in EXCEL, but not very large, such as 0.1 million, and the data is not complex, it can be exported normally if the memory is sufficient and the network is not disconnected. Data that exceeds the maximum row or column of an Excel file is displayed in the next Sheet. However, there are limits on the number of rows and columns in Excel. For example, the maximum number of lines in Excel2003 is 65536, and the maximum number of columns is 256.

4.1.2 The server cannot afford

The main tolerable range is that the data volume is large and very large. For example, the export may fail due to memory limitations. However, when the export result is opened, the Excel file that fails to be exported is invalid.

The main reason for these two export results is the size of the data volume and the complexity of the data (number of columns). If the row engine is not used, there will be a critical point, when the value is lower than the critical point, the exported content can be exported successfully, that is, the exported content has multiple sheets. Otherwise, the export fails and the content is invalid. Therefore, for reports with large data volumes, a row engine is usually used for presentation. In this case, Excel is always exported successfully. When you export an Excel worksheet for a big data engine, it is divided into multiple. XLS files and transmitted to the client in the format of a compressed package file.

4.2 enable the row engine to export large data reports

For reports with large data volumes, a row engine is usually used for presentation. In this case, Excel is always exported successfully. When a big data report in the line engine is used to export an Excel file, it is divided into multiple. XLS files and transmitted to the client in the format of a compressed package file.

For example, if a large data volume report contains rows of data, a row engine is set to display 30 rows per page. The exported results will be 41 Excel files. The first 40 Excel files have 24990 rows, the last Excel file has 400 rows, and the 41 Excel files are compressed into a zip package and uploaded to the client for download.

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.