datagrid to excel question

G

Guest

I have an app with 2 datagrids that are displayed in a page_load event.

I use the following code to render it to an Excel workbook.

sFile = sFile.Replace("/", "-")

ClearControls(DataGrid1)

Select Case RbtnExport.SelectedItem.Value

Case "Excel"

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

Response.AppendHeader("content-disposition", "attachment; filename=" & sFile
& ".xls")

Case "Word"

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

Response.AppendHeader("content-disposition", "attachment; filename=" & sFile
& ".doc")

End Select

' Remove the charset from the Content-Type header.

Response.Charset = ""

' Turn off the view state.

Me.EnableViewState = False

Dim tw As New System.IO.StringWriter

Dim hw As New System.Web.UI.HtmlTextWriter(tw)

' Get the HTML for the control.

DataGrid1.RenderControl(hw)

' Write the HTML back to the browser.

Response.Write(tw.ToString())



I know that I could create another excel spreadsheet and do the 2nd
datagrid, but would like to put the 2nd datagrid in a workbook inside the
same spreadsheet as the first one.



Is there a way to do this?



Thanks


SC
 
A

Alvin Bruney [MVP]

nope, not unless you use frames to partition the page. actually a frameset
is a good idea now that i think about it because you can make the borders
seemless so it appears as if it is one page.
 
G

Guest

Is there any way to put frames into an existing aspx page?


Thanks for the input.

SC



Alvin Bruney said:
nope, not unless you use frames to partition the page. actually a frameset
is a good idea now that i think about it because you can make the borders
seemless so it appears as if it is one page.

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/27cok
I have an app with 2 datagrids that are displayed in a page_load event.

I use the following code to render it to an Excel workbook.

sFile = sFile.Replace("/", "-")

ClearControls(DataGrid1)

Select Case RbtnExport.SelectedItem.Value

Case "Excel"

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

Response.AppendHeader("content-disposition", "attachment; filename=" &
sFile
& ".xls")

Case "Word"

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

Response.AppendHeader("content-disposition", "attachment; filename=" &
sFile
& ".doc")

End Select

' Remove the charset from the Content-Type header.

Response.Charset = ""

' Turn off the view state.

Me.EnableViewState = False

Dim tw As New System.IO.StringWriter

Dim hw As New System.Web.UI.HtmlTextWriter(tw)

' Get the HTML for the control.

DataGrid1.RenderControl(hw)

' Write the HTML back to the browser.

Response.Write(tw.ToString())



I know that I could create another excel spreadsheet and do the 2nd
datagrid, but would like to put the 2nd datagrid in a workbook inside the
same spreadsheet as the first one.



Is there a way to do this?



Thanks


SC
 

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,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top