473,799 Members | 2,941 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(D ataGrid1)

Select Case RbtnExport.Sele ctedItem.Value

Case "Excel"

Response.Conten tType = "applicatio n/vnd.ms-excel"

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

Case "Word"

Response.Conten tType = "applicatio n/vnd.ms-word"

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

End Select

' Remove the charset from the Content-Type header.

Response.Charse t = ""

' Turn off the view state.

Me.EnableViewSt ate = False

Dim tw As New System.IO.Strin gWriter

Dim hw As New System.Web.UI.H tmlTextWriter(t w)

' Get the HTML for the control.

DataGrid1.Rende rControl(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 1372
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******** ******@TK2MSFTN GP10.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(D ataGrid1)

Select Case RbtnExport.Sele ctedItem.Value

Case "Excel"

Response.Conten tType = "applicatio n/vnd.ms-excel"

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

Case "Word"

Response.Conten tType = "applicatio n/vnd.ms-word"

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

End Select

' Remove the charset from the Content-Type header.

Response.Charse t = ""

' Turn off the view state.

Me.EnableViewSt ate = False

Dim tw As New System.IO.Strin gWriter

Dim hw As New System.Web.UI.H tmlTextWriter(t w)

' Get the HTML for the control.

DataGrid1.Rende rControl(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******** ******@TK2MSFTN GP09.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******** ******@TK2MSFTN GP10.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(D ataGrid1)

Select Case RbtnExport.Sele ctedItem.Value

Case "Excel"

Response.Conten tType = "applicatio n/vnd.ms-excel"

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

Case "Word"

Response.Conten tType = "applicatio n/vnd.ms-word"

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

End Select

' Remove the charset from the Content-Type header.

Response.Charse t = ""

' Turn off the view state.

Me.EnableViewSt ate = False

Dim tw As New System.IO.Strin gWriter

Dim hw As New System.Web.UI.H tmlTextWriter(t w)

' Get the HTML for the control.

DataGrid1.Rende rControl(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
10930
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 appreciated.. Thanks CODE: private void ExportToExcel()
2
2481
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 = Session("User") & "-Customer List-" & Today() sFile = sFile.Replace("/", "") RbtnExport.Visible = False Select Case RbtnExport.SelectedItem.Value Case "Excel" Response.ContentType = "application/x-msexcel"
2
290
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) Select Case RbtnExport.SelectedItem.Value
3
1809
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 found on google: MyDataGrid.EnableViewState = false; MyPage.Response.Clear(); MyPage.Response.Buffer = true; MyPage.Response.AddHeader( "Content-disposition",
1
2139
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" Response.Charset = "" Response.AddHeader("Content-Disposition", "attachment;filename=Statement.xls") Me.EnableViewState = False
2
2871
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 how to do this ? But. my other problem is my excel sheet if setup for two columns of formatting, and I would like to paste the data into column 1 until it gets to cell 30, then if there is more than 30 records, paste them into the second column...
5
1834
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 System.IO.StringWriter Dim hw As New System.Web.UI.HtmlTextWriter(tw) ' Get the HTML for the control.
4
3955
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 out at this point. What I have is this : Members.aspx file:
0
5270
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 there but invisible. I am unable to change any type of properties within excel to have the font color change. I have tried changing every attribute on the datagrid that I can think of, and I have also outputted to just a plain generic auto-generate...
6
2740
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 the event handler for a form button. Is there other ways to accomplish this? I looked at some on the web and usergroups, but was confused as to the functioning. BTW my datagrid is enclosed in a <div></divfor ease of scrolling if that would...
0
9540
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10475
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10250
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10026
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9068
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7564
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.