反饋已提交

網絡繁忙

當前為10.0版本文檔,更多實例內容將在最新幫助文檔中展現,點選跳轉至 最新版幫助文檔

Excel 导出的多种方式

1. 描述

在导出章节中我们介绍了 Excel 导出方式 ExcelExporter,此为原样导出。若是您先前学习过 FineReport 学习教程,您会知道,在 FineReport 中,除原样导出外还有另外三种导出方式:分页导出、分页分 sheet 导出、大数据量导出。在程序中有不同的接口来实现:

1.1 原样导出 Excel2003


//原样导出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()));


1.2 原样导出 Excel2007


//原样导出excel2007
           outputStream = new FileOutputStream(new File("C:\\test\\ExcelExport.xlsx"));  
           StreamExcel2007Exporter excel1 = new StreamExcel2007Exporter();
           excel.export(outputStream, workbook.execute(parameterMap,new WriteActor()));


1.3 分页导出 Excel2003


//分页导出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()));


1.4 分页导出 Excel2007


//分页导出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()));


1.5 分页分 sheet 导出 Excel2003


//分页分sheet导出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()));


1.6 分页分 sheet 导出 Excel2007


//分页分sheet导出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()));


1.7 大数据量导出

大数据量导出默认是 65512 行的 .xls 组成的压缩包


//大数据量导出
            outputStream = new FileOutputStream(new File("C:\\test\\LargeExcelExport.zip"));
            LargeDataPageExcelExporter large = new LargeDataPageExcelExporter(ReportUtils.getPaperSettingListFromWorkBook(workbook.execute(parameterMap,new WriteActor())), true);
            //导出2007版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()));


2. 示例

2.1 完整可执行代码详见:

https://code.fanruan.com/demo/example/src/release/10.0/src/main/java/com/fr/io/ExportExcel.java

注:工程路径需要根据实际情况修改

编译运行该代码后,就会在对应路径下生成不同格式的文件,这样就导出成功了,如下图:


222

附件列表


主題: 原简体文档
已經是第一篇
已經是最後一篇
  • 有幫助
  • 沒幫助
  • 只是瀏覽
  • 圖片不清晰
  • 用語看不懂
  • 功能說明看不懂
  • 操作說明太簡單
  • 內容有錯誤

文 檔回 饋

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

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

不再提示

10s後關閉