472,133 Members | 1,071 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,133 software developers and data experts.

Export DataGrid to Excel problem

When i export DataGrid to Excel all the HTML contents are also exporting to
excel. i am using stylesheets in the ASPX Page and i am getting an alert
message that stylesheets are missing. i need to export only the contents of
the Datagrid to excel. i don't need all other stuff which is present on the
page. is there any way to achieve it.

Thanks in Advance
Nov 19 '05 #1
3 4240
try this...

Response.Clear()
Response.Buffer = True
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Dim oStringWriter As New System.IO.StringWriter
Dim oHtmlTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter)

oHtmlTextWriter.Write("<html><head>")

oHtmlTextWriter.Write("<style>")
oHtmlTextWriter.Write(".dataGridHeader{font-weight: bold;font-size:
8pt;color: black;font-family: Verdana;background-color: #ddddee;text-align:
left;}")
oHtmlTextWriter.Write(".dataGridItemStyle{font-size: 8pt;color:
black;font-family: Verdana;text-align: left;}")

oHtmlTextWriter.Write("</style>")
oHtmlTextWriter.Write("</head><body>")

oHtmlTextWriter.WriteBeginTag("form runat=server ")
oHtmlTextWriter.WriteAttribute("target", "_blank")
oHtmlTextWriter.Write(">")
dgReport.RenderControl(oHtmlTextWriter)
oHtmlTextWriter.Write("</form></body></html>")
Response.Write(oStringWriter.ToString())
Response.End()

--
http://pathidotnet.blogspot.com
=====
vInAypAtHi
o__
---_,>/'_------
(_) \(_)
---------------
"Bidarkota" wrote:
When i export DataGrid to Excel all the HTML contents are also exporting to
excel. i am using stylesheets in the ASPX Page and i am getting an alert
message that stylesheets are missing. i need to export only the contents of
the Datagrid to excel. i don't need all other stuff which is present on the
page. is there any way to achieve it.

Thanks in Advance

Nov 19 '05 #2
Well that depends on what technique you are using to export the datagrid.
There are a variety of ways to export ASP.NET content to Excel.
Most of the techniques are described in detail here:
http://SteveOrr.net/articles/ExportPanel.aspx
http://SteveOrr.net/articles/ExcelExport.aspx

These examples remove all the extra HTML "stuff" you're talking about.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Bidarkota" <pr******@yahoo.com> wrote in message
news:DC**********************************@microsof t.com...
When i export DataGrid to Excel all the HTML contents are also exporting
to
excel. i am using stylesheets in the ASPX Page and i am getting an alert
message that stylesheets are missing. i need to export only the contents
of
the Datagrid to excel. i don't need all other stuff which is present on
the
page. is there any way to achieve it.

Thanks in Advance

Nov 19 '05 #3
Thank you vinay and Steve. My problem is solved.

"Steve C. Orr [MVP, MCSD]" wrote:
Well that depends on what technique you are using to export the datagrid.
There are a variety of ways to export ASP.NET content to Excel.
Most of the techniques are described in detail here:
http://SteveOrr.net/articles/ExportPanel.aspx
http://SteveOrr.net/articles/ExcelExport.aspx

These examples remove all the extra HTML "stuff" you're talking about.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Bidarkota" <pr******@yahoo.com> wrote in message
news:DC**********************************@microsof t.com...
When i export DataGrid to Excel all the HTML contents are also exporting
to
excel. i am using stylesheets in the ASPX Page and i am getting an alert
message that stylesheets are missing. i need to export only the contents
of
the Datagrid to excel. i don't need all other stuff which is present on
the
page. is there any way to achieve it.

Thanks in Advance


Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by | last post: by
2 posts views Thread by C | last post: by
2 posts views Thread by Bidarkota | last post: by
5 posts views Thread by Reggie | last post: by
1 post views Thread by Reggie | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.