473,379 Members | 1,260 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

datagrid to excel question

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


Nov 18 '05 #1
2 1351
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
<me@privacy.net> wrote in message
news:ux**************@TK2MSFTNGP10.phx.gbl...
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


Nov 18 '05 #2
Is there any way to put frames into an existing aspx page?
Thanks for the input.

SC

"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
news:eB**************@TK2MSFTNGP09.phx.gbl...
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
<me@privacy.net> wrote in message
news:ux**************@TK2MSFTNGP10.phx.gbl...
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



Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ugo | last post by:
Hi, I am having a problem exporting a Datagrid to excel in asp.net. For some reason I am getting a blank excel page. I set up in IIS the Mime for ..xls. My code is below any help would be...
2
by: Steve Chatham | last post by:
I use the following code: Private Sub RbtnExport_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RbtnExport.SelectedIndexChanged Dim sFile As String =...
2
by: | last post by:
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) ...
3
by: nkunkov | last post by:
Hi, I have read a lot of articles in this newsgroup about how to solve this problem but found no solution. I'm trying to export a C# datagrid to Excel file. Here is my code that I have also...
1
by: Ed Chiu | last post by:
Hi, I copied the following codes from Internet to export datagrid to Excel, it works with datagrid not supporting sorting or paging. Response.ContentType = "application/vnd.ms-excel"...
2
by: TM | last post by:
I have an Excel sheet where I setup my needed formatting, page settings, ect, and would like to take my data from a datagrid and paste it into the excel file and print the excel file. Any idea...
5
by: Dave | last post by:
In a VB.NET application, I have a datagrid that I export to an Excel spreadsheet like this: ' Set the content type to Excel Response.ContentType = "application/vnd.ms-excel" Dim tw As New...
4
by: Frank | last post by:
Hello All, I ham using VS.NET 2003. Have followed instructions from http://gridviewguy.com/ArticleDetails.aspx?articleID=26 along with several other articles to no avail. I am pulling my hair...
0
by: letsgetsilly | last post by:
I am populating a datagrid and outputting it to excel. Everything worked well last night, but today excel only displays the content in font color white, which is impossible to see. The data is all...
6
by: slinky | last post by:
I found the following code to transfer datagrid data to an Excel file. Is this written in C#?... I'm a vb.netter. I'm just not sure where to place the code to experiment on it. Should I place it in...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.