datagrid to excel question

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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.
 
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
 
Back
Top