简体   繁体   中英

ReportViewer - How can I render Excel files with more than 65,000 rows?

I am using a ReportViewer control to export the report data to Excel. Everything works fine except when I try to export data that has more than ~65,000 rows it throws an exception.

Is there any work-around I can use to possibly render the report in multiple sheets? Thanks!

Excel 2005 and earlier only support 65536 rows per sheet.

Excel 2007 and 2010 support 1048576 rows per sheet .

That said, the limit for ReportViewer exporting to Excel may be only 65536. Exporting in CSV format would get you around this limitation.

To overcome the limitation error, RDLC provides an option to break the pages into multiple sheets.

在此处输入图片说明

Example

Create a sample RDLC report with Report Viewer 10.0, using Adventure Works database, which is displaying above 66000 records.

By applying the steps, mentioned below in RDLC report, the large data can be easily exportable into multiple sheets.

Step 1

Open RDLC and select the data row of the table. Right-click on it, select Add Group and then select Parent Group.

Step 2

In this step, you should get a Tablix group Window. Enter the function, mentioned below in the Group by Text box and click OK.

=Int((RowNumber(Nothing))/65520)

Step 3

In the next step, at the bottom of the RDLC report, you will find “Row Groups” pane. Here, right-click on the group name and select Group Properties.

  1. You will get a Group Properties Window. We can give a proper group name here.

  2. Check the “Between each instance of a group” option in Page Breaks from the left pane.

  3. Next, in the Sorting section, delete the sort by function.

If you observe the report after performing the steps mentioned above, it adds the Group1 column, as shown below. Select add delete the Column.

Now, save & run the report and export to Excel format. If everything works, the data should display in the multiple sheets.

If we observe in sheet 2, the report headers won't display. In order to display the headers, add the code, mentioned below.

Open the RDLC report in the XML editor. Add the nodes, mentioned below at the first TablixMember node of TablixMembers node.

<KeepWithGroup>After</KeepWithGroup> <RepeatOnNewPage>true</RepeatOnNewPage>

Save, rerun the report and export to Excel. You can observe the data in multiple sheets with the headers in all the sheets.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM