Multiple Ways To Export Excel

  • Last update:  2020-12-17
  • I. Overview

    Apart from ExcelExporter, i.e. Unaltered Export, which has been covered in the Export section,  FineReport offers three additional export methods, namely, Pagination Export, Page to Sheet Export and Large Data Volume Export. The corresponding interfaces are provided to implement these methods in your projects.

    1. Unaltered Export (Excel2003)

    //Unaltered Export (Excel2003)
    outputStream = new FileOutputStream(new File("C:\\test\\ExcelExport.xls"));  
    ExcelExporter excel = new ExcelExporter();  
    excel.setVersion(true);
    excel.export(outputStream, workbook.execute(parameterMap,new WriteActor()));

    2. Unaltered Export (Excel2007)

    //Unaltered Export (Excel2007)
    outputStream = new FileOutputStream(new File("C:\\test\\ExcelExport.xlsx"));  
    StreamExcel2007Exporter excel1 = new StreamExcel2007Exporter();
    excel.export(outputStream, workbook.execute(parameterMap,new WriteActor()));

    3. Pagination Export (Excel2003)

    //Pagination Export (Excel2003)
    outputStream = new FileOutputStream(new File("C:\\test\\PageExcelExport.xls"));
    PageExcelExporter page = new PageExcelExporter(ReportUtils.getPaperSettingListFromWorkBook(workbook.execute(parameterMap,new WriteActor())));
    page.setVersion(true);
    page.export(outputStream, workbook.execute(parameterMap,new WriteActor()));

    4. Pagination Export (Excel2007)

    //Pagination Export (Excel2007)
    outputStream = new FileOutputStream(new File("C:\\test\\PageExcelExport.xlsx")); 
    PageExcel2007Exporter page1 = new PageExcel2007Exporter(ReportUtils.getPaperSettingListFromWorkBook(rworkbook));
    page1.export(outputStream, workbook.execute(parameterMap,new WriteActor()));

    5. Page to Sheet Export (Excel2003)

    //Page to Sheet Export (Excel2003)
    outputStream = new FileOutputStream(new File("C:\\test\\PageSheetExcelExport.xls"));
    PageToSheetExcelExporter sheet = new PageToSheetExcelExporter(ReportUtils.getPaperSettingListFromWorkBook(workbook.execute(parameterMap,new WriteActor())));
    sheet.setVersion(true);
    sheet.export(outputStream, workbook.execute(parameterMap,new WriteActor()));

    6. Page to Sheet Export (Excel2007)

    //Page to Sheet Export (Excel2007)
    outputStream = new FileOutputStream(new File("C:\\test\\PageSheetExcelExport.xlsx"));
    PageToSheetExcel2007Exporter sheet1 = new PageToSheetExcel2007Exporter(ReportUtils.getPaperSettingListFromWorkBook(rworkbook));
    sheet1.export(outputStream, workbook.execute(parameterMap,new WriteActor()));

    7. Large Data Volume Export

    This option will export an archived .xls file with 65512 rows by default.

    //Large Data Volume Export
    outputStream = new FileOutputStream(new File("C:\\test\\LargeExcelExport.zip"));
    LargeDataPageExcelExporter large = new LargeDataPageExcelExporter(ReportUtils.getPaperSettingListFromWorkBook(workbook.execute(parameterMap,new WriteActor())), true);
    outputStream = new FileOutputStream(new File("C:\\test\\LargeExcelExport.xlsx")); LargeDataPageExcel2007Exporter large = new LargeDataPageExcel2007Exporter(ReportUtils.getPaperSettingListFromWorkBook(rworkbook), true);
    large.export(outputStream, workbook.execute(parameterMap,new WriteActor()));

    II. Example

    1. Detailed Executable Codes

    https://github.com/finereport-overseas/example/blob/release/10.0/src/main/java/com/fr/io/ExportExcel.java

    Note: the project path needs to be modified accordingly.

    As shown below, files with different formats will be created in corresponding paths once you have successfully compiled and run the code.

    toIfKdeRRcEwPXJp__thumbnail.png


    Attachment List


    Theme: Secondary Development
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy