cancel
Showing results for 
Search instead for 
Did you mean: 

export Datagrid to Excel

Former Member
0 Kudos

Hi All,

can we export the DataGrid to excel from .net iviews?. i tried with the following code it works fine in the aspx page but in the portal iview its not working, can anyone pls let me know how to go about it

here is the code i tried

Private Sub btnDownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

Response.Clear()

Response.Buffer = True

Response.ContentType = "application/vnd.ms-excel"

Response.Charset = ""

Me.EnableViewState = False

Dim oStringWriter As New System.IO.StringWriter

Dim oHtmlTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter)

DataGrid1.RenderControl(oHtmlTextWriter)

Response.Write(oStringWriter.ToString())

Response.End()

End Sub

thanks

Murali.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Murali,

Note that it should only work when the iView's isolation mode is set to URL.

Anyway, doesn't this way (putting the code in the button click) pose the problem of further navigation (after the file has downloaded)? I think a nicer UI way would be to put a url on a page which will point to the same PortalComponent, which a query parameter, and add this same code in the page load, asking for the query string. similar to what is in this "how-to":

https://media.sdn.sap.com/html/submitted_docs/dotnet/How%20to/ThirdPartyChartControl.htm

Regards,

Ofer

Former Member
0 Kudos

Hi Murali

Since Portal Applications are not standard asp.net Web Applications it requires some mild modification.

try the following code instead:

Response.ContentType = "application/vnd.ms-excel";

StringWriter sw = new StringWriter();

HtmlTextWriter htw = new HtmlTextWriter(sw);

DataGrid1.RenderControl(htw);

Response.Write(sw.ToString());

Mind my (c#) lang.

You can also look at another sample of changing the response content type at https://media.sdn.sap.com/html/submitted_docs/dotnet/How%20to/Content%20Type.htm

Cheers,

Tsachi