ReportViewer With Page Breaks vs. Excel Without

D

Dave

Using VS2008 web applicaiton with the ReportViewer.

Have a report that has (and needs) page breaks. When this report is
exported to Excel, we need the report to appear on one sheet instead of one
sheet per page. Is there a way to accomplish this?

On a slightly different topic, there are textboxes on the report that span
several lines. When these appear in Excel, the heigh of the cell is set so
that only the first line is visible. Is there a way to get excel to
automatically adjust the cell height to display the full contents?
 
J

Jialiang Ge [MSFT]

Hello,

From your post, my understanding on this issue is: you wonder (1) How to
export contents separated with page breaks in a rdlc to *one* worksheet,
and (2) How to make the report viewer adjust the exported worksheet cell's
height to fit the content of textboxes in the rdlc. If I'm off base, please
feel free to let me know.

For you first question "How to export contents separated with page breaks
in a rdlc to *one* worksheet", I have to let you know that it is a
by-design behavior of the Report Viewer control to export the report to
several worksheets when there are page breaks in it. We are not able to
interfere with the action when the control is exporting the content to a
xls.

However, a possible solution is:
1. Set the report viewer control's ShowExportControls = False
2. Add a new rdlc which is copied from your original rdlc, then remove all
the page breaks in it so that the new rdlc will be rendered to only one
page.
3. Add a button ("Generate Excel Report") to the web page, in the button's
Click event handler, add the following:
ReportViewer rv = new ReportViewer();
rv.ProcessingMode = ProcessingMode.Local;
rv.LocalReport.ReportPath = Server.MapPath("Report2.rdlc"); //
point to the new rdlc without page breaks
rv.LocalReport.DataSources.Clear();
rv.LocalReport.DataSources.Add(...); // your report data source
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;
byte[] bytes = rv.LocalReport.Render("EXCEL", null, out mimeType,
out encoding, out extension, out streamids, out warnings);

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType =
"application/vnd.ms-excel";
HttpContext.Current.Response.AddHeader("Content-disposition",
"attachment; filename=Report.xls");
HttpContext.Current.Response.BinaryWrite(bytes);
HttpContext.Current.Response.End();
Please have a try and let me know if it works for you.

For your second question "How to make the report viewer adjust the exported
worksheet cell's height to fit the content of textboxes in the rdlc.":
Based on my test, the cells in the worksheet generated by the report viewer
have been adjusted to the proper height. Here is my test steps:
1. Drag and drop a Textbox from Report Items Toolbox to the rdlc
2. Resize the Textbox control to 1.25in, 0.375in, and type a very long text
into it.
If I set the Textbox's CanGrow property as False, the generated report and
excel file shows the textbox as size: 1.25in, 0.375in.
If I set the Textbox's CanGrow property as True, the generated report and
excel file will adjust the textbox's height so that all the text in it can
be shown.

I am not able to reproduce the issue that "only the first line is displayed
in the generated worksheet". Am I misunderstanding your question? Or would
you send a sample to my mailbox so that I can have a clearer picture of the
problem? My mailbox: (e-mail address removed), remove 'nospam.'

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top