Export ListView to Excel

by jrose 8/20/2010 10:02:00 AM

All results that I came across when performing a search for export listview to excel were related to instances of Windows.Forms.ListView and not System.Web.UI.WebControls.ListView.

 

Attached are the two functions necessary to export instances of System.Web.UI.WebControls.ListView to Excel.

public override void VerifyRenderingInServerForm(Control control) { }

protected void btnExport_Click(object sender, EventArgs e)
{
    Response.Clear();
    Response.Buffer = true;
    Response.ContentType = "application/vnd.ms-excel";
    Response.Charset = "";
    this.EnableViewState = false;
    StringWriter stringWriter = new StringWriter();
    HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
    listView.RenderControl(htmlTextWriter);
    Response.Write(stringWriter.ToString());
    Response.End();
}

Tags: , , ,

.NET | ASP.NET AJAX | Excel Programming

ReportViewer Control: Fit to Page

by jrose 5/11/2010 9:09:00 AM

The ReportViewer control's export functionality can be temperamental.

 

In order to guarantee that the exported file will not be wider than a page, use the following formula:

Body.Size.Width + Report.Margins.Left + Report.Margins.Right <= Report.PageSize.Width

 

(since, in our case, InteractiveSize and PageSize are the same, this means InteractiveSize can be substituted in PageSize above)

Tags: , , ,

.NET | VB.NET

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen

About the author

Name of author Author name
Something about me and what I do.

E-mail me Send mail

Calendar

<<  July 2017  >>
MoTuWeThFrSaSu
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

View posts in large calendar

Recent comments

Tags

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2017

Sign in